取服务器端URL文件长度

//在MFC工程中,取url中的文件长度,发现只有libcurl7.36版本可用,7.37、7.38都不行,不知道是什么原因。
//但是Console工程可以。
CURLcode GetTotalFileLenth(const char* url, double& dbLen)
{
	double downloadFileLenth = 0;

	CURLcode res;

	CURL* pCurl = curl_easy_init();
	curl_easy_setopt(pCurl, CURLOPT_URL, url);
	curl_easy_setopt(pCurl, CURLOPT_HEADER, 1L);
	curl_easy_setopt(pCurl, CURLOPT_NOBODY, 1L);
	//curl_easy_setopt(pCurl, CURLOPT_VERBOSE, 1L);
	res = curl_easy_perform(pCurl);

	if (res == CURLE_OK)
	{
		curl_easy_getinfo(pCurl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &downloadFileLenth);
	}
	else
	{
		downloadFileLenth = -1;
	}
	curl_easy_cleanup(pCurl);

	dbLen = downloadFileLenth;

	return res;
}

你可能感兴趣的:(取服务器端URL文件长度)