Libcurl HTTP GET to get JSON data (reprint)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.