Curl is a powerful HTTP operation library that can be used to perform HTTP operations, reducing the complexity of using socket in code. it also contains a file transfer tool curl that uses the URL syntax to work under the command line. specific can refer to: http://curl.haxx.se/This is the home page of the curl developer.
The following is my example to test the HTTP returned data.
# Include <stdio. h> <br/> # include <curl/curl. h> <br/> // page data callback function <br/> static size_t write_callback (void * PTR, size_t size, size_t nmemb, void * Stream) <br/>{< br/> int Len = size * nmemb; <br/> int written = Len; <br/> fwrite (PTR, size, nmemb, (File *) stream); <br/> // written = fputs (PTR, (File *) stream); <br/> return written; <br/>}< br/> // return the HTTP header callback function <br/> static size_t header_callback (void * PTR, size_t size, size_t nmemb, void * Stream) <br/>{< br/> int Len = size * nmemb; <br/> int written = Len; <br/> return written; <br/>}</P> <p> int main (void) <br/>{< br/> curl * curl; <br/> curlcode res; <br/> struct curl_slist * chunk = NULL; </P> <p> curl = curl_easy_init (); <br/> If (curl) {</P> <p> // Add HTTP header Additional Information <br/> chunk = curl_slist_append (chunk, "Accept-language: ZH-CN "); <br/> // chunk = curl_slist_append (chunk, "accept: image/GIF, image/X-xbitmap, image/JPEG, image/pjpeg, application/X-Shockwave-flash, */* "); <br/> chunk = curl_slist_append (chunk," Accept-encoding: gzip, deflate "); <br/> chunk = curl_slist_append (chunk, "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; CBA )"); <br/> chunk = curl_slist_append (chunk, "connection: keep-alive"); <br/> // set the debugging mode <br/> curl_easy_setopt (curl, curlopt_verbose, 1l); <br/> curl_easy_setopt (curl, curlopt_url, "192.168.1.25"); <br/> curl_easy_setopt (curl, curlopt_httpheader, Chunk ); </P> <p> // set callback function <br/> curl_easy_setopt (curl, curlopt_headerfunction, header_callback); <br/> curl_easy_setopt (curl, curlopt_writefunction, write_callback ); </P> <p> res = curl_easy_perform (curl); </P> <p>/* always cleanup */<br/> curl_easy_cleanup (curl ); </P> <p> curl_slist_free_all (chunk); <br/> chunk = NULL; <br/>}< br/> return 0; <br/>}< br/>