C++ Http下载文件
#include <windows.h>
#include <tchar.h>
#pragma comment(lib,"urlmon.lib")
#pragma comment(lib,"ws2_32.lib")
string url = "http://a3.att.hudong.com/14/75/01300000164186121366756803686.jpg";
size_t len = url.length();
int nmlen = MultiByteToWideChar(CP_ACP, 0, url.c_str(), len + 1, NULL, 0);
wchar_t* buffer = new wchar_t[nmlen];
MultiByteToWideChar(CP_ACP, 0, url.c_str(), len + 1, buffer, nmlen);
HRESULT hr = URLDownloadToFile(NULL, buffer, _T("E:\\sky.jpg"), 0, NULL);
if (hr == S_OK)
{
cout << "Download File Is Success" << endl;
}
下载结果截图