linux 下C编程实现 curl 和libcurl
linux 下C编程实现 如何实现命令行中curl "http://www.google.cn/maps/vt?lyrs=s@174&gl=cn&x=208&y=105&z=8" > a.jpg 一样的效果。
我的代码如下,发现对googlemap用命令行和代码返回不同,命令行可以返回,代码写不可以。下面代码用其他url试过是可行的
CURLcode res;
char* result = "error";
res = curl_global_init(CURL_GLOBAL_ALL);
if (res != CURLE_OK)
{
printf( "Failed to global init default [%d]\n", res );
}
CURL* pEasyHandle = curl_easy_init();
curl_easy_setopt(pEasyHandle, CURLOPT_URL, url);
curl_easy_setopt(pEasyHandle, CURLOPT_WRITEFUNCTION, &process_data);
curl_easy_setopt(pEasyHandle, CURLOPT_TIMEOUT, 10);
curl_easy_setopt(pEasyHandle, CURLOPT_FORBID_REUSE, 1);
FILE *pFile = fopen(jpgfilename, "w");
curl_easy_setopt(pEasyHandle, CURLOPT_WRITEDATA, pFile);
res = curl_easy_perform(pEasyHandle);
curl_easy_cleanup(pEasyHandle);
curl_global_cleanup();
fclose(pFile);