参考官方网http://curl.haxx.se/
比如实现以个http的get方法,比如 http://www.baidu.com/s?wd=test
注意在下载vc版库的有可能会少一个zlib1.dll的库,注意下载。
代码示例:
CURL * curl = curl_easy_init();
int ct = -1; //状态码记录
Ret = 0;
if(curl) {
CURLcode res;
res = curl_easy_setopt(curl, CURLOPT_URL, "http://www.baidu.com/s?wd=test");
res = curl_easy_setopt(curl, CURLOPT_TIMEOUT,6);//6秒request超时
res = curl_easy_perform(curl);
if(CURLE_OK == res) {
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &ct);
}else
{
Ret = 1;
}
//always cleanup
curl_easy_cleanup(curl);
}
libcurl 实现了很多平台。非常适合开发基于http等协议的接口。
比如实现以个http的get方法,比如 http://www.baidu.com/s?wd=test
注意在下载vc版库的有可能会少一个zlib1.dll的库,注意下载。
代码示例:
CURL * curl = curl_easy_init();
int ct = -1; //状态码记录
Ret = 0;
if(curl) {
CURLcode res;
res = curl_easy_setopt(curl, CURLOPT_URL, "http://www.baidu.com/s?wd=test");
res = curl_easy_setopt(curl, CURLOPT_TIMEOUT,6);//6秒request超时
res = curl_easy_perform(curl);
if(CURLE_OK == res) {
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &ct);
}else
{
Ret = 1;
}
//always cleanup
curl_easy_cleanup(curl);
}
libcurl 实现了很多平台。非常适合开发基于http等协议的接口。
使用libcurl实现HTTP GET请求
本文介绍如何使用libcurl库实现HTTP GET请求,并提供了一个简单的示例代码,包括设置URL、请求超时时间和获取响应状态码的过程。此外还提到了在使用VC编译时可能遇到的缺少zlib1.dll的问题。
3万+

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



