#include<iostream>
#include<string>
#include<curl\curl.h>
using namespace std;
static size_t downloadCallback(void *buffer, size_t sz, size_t nmemb, void *writer)
{
string* psResponse = (string*) writer;
size_t size = sz * nmemb;
psResponse->append((char*) buffer, size);
return sz * nmemb;
}
int main()
{
system("chcp 65001");
system("cls");
string strUrl = "http://www.txttool.com";
string strTmpStr;
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 2);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, downloadCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &strTmpStr);
CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
string strRsp;
if (res != CURLE_OK)
{
strRsp = "error";
}
else
{
strRsp = strTmpStr;
}
cout<<strRsp.c_str()<<endl;
// printf("strRsp is |%s|\n", strRsp.c_str());
return 0;
}
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询