入门使用libcurl库,实现c++应用与javaweb应用强配合

参考官方网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等协议的接口。

你可能感兴趣的:(C++,c,C#,vc++)