#include "stdafx.h"
#include "curl.h"
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#pragma comment(lib, "libcurl.lib" )
#pragma comment (lib, "ws2_32.lib" )
#pragma comment (lib, "winmm.lib" )
#pragma comment (lib, "wldap32.lib")
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main(void)
{
CURL *curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.dolit.cn/index.html");
curl_easy_setopt( curl, CURLOPT_CONNECTTIMEOUT, 3 );
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
std::cout << "test libcurl" << std::endl;
std::cout << res << std::endl;
std::cout << readBuffer << std::endl;
}
return 0;
}
vs2008 使用编译好的libcurl.lib 静态库的 示例代码
最新推荐文章于 2022-08-20 09:50:03 发布
本文展示了一个使用libcurl库进行HTTP请求的C++代码示例,包括了初始化CURL句柄、设置URL、超时时间、写回调函数等关键步骤,并演示了如何读取响应数据。
2343

被折叠的 条评论
为什么被折叠?



