標籤:ref error http ring function orm str func sdn
轉載:http://blog.csdn.net/vincent2610/article/details/68488365
#include <stdio.h>#include <iostream>#include <sstream>using namespace std;size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { string data((const char*) ptr, (size_t) size * nmemb); *((stringstream*) stream) << data << endl; return size * nmemb;}int main(int argc, char *argv[]){ // 基於當前系統的當前日期/時間 time_t now = time(0); char* dt = ctime(&now); cout << dt << "-------------------------------------" << endl; /*HTTP GET json data*/ std::stringstream out; void* curl = curl_easy_init(); // 設定URL curl_easy_setopt(curl, CURLOPT_URL, "http://if.qdocument.net:705/bic/download/[email protected]&pageNum=1"); // 設定接收資料的處理函數和存放變數 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out); // 執行HTTP GET操作 CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } // 接受資料存放在out中,輸出之 //cout << out.str() << endl; string str_json = out.str(); printf("%s",str_json.c_str()); curl_easy_cleanup(curl); return 0;}
libcurl進行HTTP GET擷取JSON資料(轉載)