从直接下载 URL 下载 URL 文件? | C++
Download URL File from Direct Download URL? | C++
所以基本上我正在尝试从 URL(不是从 HTML/PHP)直接下载 link 下载文件,例如:https://cdn.discordapp.com/attachments/0/0/file.txt. I want my program to download a certain file from a direct download link in the same directory where the application was ran, i know this is possible in C# using WebClient.DownloadFile 但是我不确定如何在 C++ 中使用类似的东西。如果你能提供帮助那就太好了,谢谢你,祝你有美好的一天。
我认为,您可以使用 URLDownloadToFile 从 url 下载文件。
我打开了你给的link但是网页报错,没有找到任何txt。因此,您可以参考下面的例子:
#include <iostream>
#include <urlmon.h>
#pragma comment(lib,"urlmon.lib")
using namespace std;
int main()
{
HRESULT hr = URLDownloadToFile(0, L"http://pic104.nipic.com/file/20160715/6171480_185807154956_2.jpg", L"D:\testfolder\sky.jpg", 0, NULL);
if (hr == S_OK)
{
cout << "ok" << endl;
}
return 0;
}
当然也可以使用第三方库,比如libcurl
。
所以基本上我正在尝试从 URL(不是从 HTML/PHP)直接下载 link 下载文件,例如:https://cdn.discordapp.com/attachments/0/0/file.txt. I want my program to download a certain file from a direct download link in the same directory where the application was ran, i know this is possible in C# using WebClient.DownloadFile 但是我不确定如何在 C++ 中使用类似的东西。如果你能提供帮助那就太好了,谢谢你,祝你有美好的一天。
我认为,您可以使用 URLDownloadToFile 从 url 下载文件。
我打开了你给的link但是网页报错,没有找到任何txt。因此,您可以参考下面的例子:
#include <iostream>
#include <urlmon.h>
#pragma comment(lib,"urlmon.lib")
using namespace std;
int main()
{
HRESULT hr = URLDownloadToFile(0, L"http://pic104.nipic.com/file/20160715/6171480_185807154956_2.jpg", L"D:\testfolder\sky.jpg", 0, NULL);
if (hr == S_OK)
{
cout << "ok" << endl;
}
return 0;
}
当然也可以使用第三方库,比如libcurl
。