使用libcurl:
size_t AppendDataToStringCurlCallback(void *ptr, size_t size, size_t nmemb, void *vstring)
{
std::string * pstring = (std::string*)vstring;
pstring->append((char*)ptr, size * nmemb);
return size * nmemb;
}
std::string DownloadUrlAsString(const std::string & url)
{
std::string body;
CURL *curl_handle;
curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, AppendDataToStringCurlCallback);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &body);
curl_easy_perform(curl_handle);
curl_easy_cleanup(curl_handle);
return body;
}
退房[的libcurl](http://curl.haxx.se/libcurl/)。 – 2012-07-31 08:38:44
這個問題如何不是另一個問題的完全重複? – 2012-07-31 08:40:30
你已經問了同樣的問題兩次,你得到了相同的'使用libcurl'的好答案。 Libcurl會做你想做的事情,XML或HTML就沒有什麼區別。如果你不準備相信你得到的答案,那麼在論壇上發帖並沒有多大意義。 – jahhaj 2012-07-31 08:40:53