Instead of fighting with libcurl you could just use WinInet for your http needs if you are married to the Windows platform.
A quick example follows, great article, and as usual pretty difficult to navigate msdn docs
#include <windows.h> #include <wininet.h> #include <stdio.h> #include <stdlib.h> #pragma comment ( lib, "Wininet.lib" ) int main() { HINTERNET hInternet = InternetOpenA("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); HINTERNET hConnection = InternetConnectA( hInternet, "you.appspot.com", 80, " "," ", INTERNET_SERVICE_HTTP, 0, 0 ); HINTERNET hData = HttpOpenRequestA( hConnection, "GET", "/", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0 ); char buf[ 2048 ] ; HttpSendRequestA( hData, NULL, 0, NULL, 0 ) ; DWORD bytesRead = 0 ; DWORD totalBytesRead = 0 ; // http://msdn.microsoft.com/en-us/library/aa385103(VS.85).aspx // To ensure all data is retrieved, an application must continue to call the // InternetReadFile function until the function returns TRUE and the // lpdwNumberOfBytesRead parameter equals zero. while( InternetReadFile( hData, buf, 2000, &bytesRead ) && bytesRead != 0 ) { buf[ bytesRead ] = 0 ; // insert the null terminator. puts( buf ) ; // print it to the screen. printf( "%d bytes read\n", bytesRead ) ; totalBytesRead += bytesRead ; } printf( "\n\n END -- %d bytes read\n", bytesRead ) ; printf( "\n\n END -- %d TOTAL bytes read\n", totalBytesRead ) ; InternetCloseHandle( hData ) ; InternetCloseHandle( hConnection ) ; InternetCloseHandle( hInternet ) ; }
One Comment
Hey, Could you please let me know where I can download Wininet library? I really have trouble to find it.. Thank you so much!! Really appreciated!