Reprint: http://blog.csdn.net/vincent2610/article/details/68488365
#include <stdio.h>#include<iostream>#include<sstream>using namespacestd;size_t Write_data (void*ptr, size_t size, size_t nmemb,void*stream) { stringData (Const Char*) PTR, (size_t) size *nmemb); * ((stringstream*) stream) << data <<Endl; returnSize *Nmemb;}intMainintargcChar*argv[]) { //Current date/time based on current systemtime_t now = time (0); Char* dt = CTime (&Now ); cout<< DT <<"-------------------------------------"<<Endl; /*HTTP GET JSON data*/Std::stringstream out; void* Curl =Curl_easy_init (); //Set URLCurl_easy_setopt (Curl, Curlopt_url,"Http://if.qdocument.net:705/bic/download/[email protected]&pagenum=1"); //set the processing function and the storage variables for the received datacurl_easy_setopt (Curl, curlopt_writefunction, write_data); Curl_easy_setopt (Curl, Curlopt_writedata,& out); //performing an HTTP GET operationCurlcode res =curl_easy_perform (Curl); if(Res! =CURLE_OK) {fprintf (stderr,"Curl_easy_perform () failed:%s\n", Curl_easy_strerror (res)); } //The accepted data is stored in the out-//cout << out.str () << Endl; stringStr_json = out. STR (); printf ("%s", Str_json.c_str ()); Curl_easy_cleanup (curl); return 0;}
Libcurl HTTP GET to get JSON data (reprint)