Reading the manual page is a wonderful thing, you should try it sometime.
Code:
#include <stdio.h>
#include <curl/curl.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <curl/types.h>
size_t write_data_balance(void *buffer, size_t size, size_t nmemb, void *userp);
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1 ); /* DEBUG - for those who RTFM */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data_balance);
curl_easy_setopt(curl, CURLOPT_URL, "http://yahoo.com");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
size_t write_data_balance(void *buffer, size_t size, size_t nmemb, void *userp)
{
char *response;
response = (char*)buffer;
/* NOT \0 terminated, so use the passed size information */
printf("*********** %.*s\n",size*nmemb,response);
return size * nmemb; /* V.Important */
}
$ gcc new.c -lcurl
$ ./a.exe
* About to connect() to yahoo.com port 80 (#0)
* Trying 66.94.234.13... * connected
* Connected to yahoo.com (66.94.234.13) port 80 (#0)
> GET / HTTP/1.1
Host: yahoo.com
Accept: */*
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 26 Oct 2007 15:03:39 GMT
< Location: http://www.yahoo.com/
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
<
*********** The document has moved <A HREF="http://www.yahoo.com/">here</A>.<P>
<!-- p1.rc.scd.yahoo.com uncompressed/chunked Fri Oct 26 08:03:39 PDT 2007 -->
* Closing connection #0