我想从一个基本上看起来像这样的 URL 下载一个字符串:
在 C# WinForms 中,我知道我可以这样做:
使用 System.Net; WebClient 客户端 = 新 WebClient(); string str = client.DownloadString("https://website.com/file.txt");
字符串将存储在str
. 我想在 C++ VCL 应用程序中做到这一点。
我想从一个基本上看起来像这样的 URL 下载一个字符串:
在 C# WinForms 中,我知道我可以这样做:
使用 System.Net; WebClient 客户端 = 新 WebClient(); string str = client.DownloadString("https://website.com/file.txt");
字符串将存储在str
. 我想在 C++ VCL 应用程序中做到这一点。
有大量可用于 C++Builder 的 HTTP 库。它甚至预装了 2 个:
Indy的TIdHTTP
组件
#include <IdHTTP.hpp>
TIdHTTP *client = new TIdHTTP();
String str = client->Get(_D("https://website.com/file.txt"));
delete client;
Embarcadero 的THTTPClient
组件:
#include <System.Net.HttpClient.hpp>
THTTPClient *client = THTTPClient::Create();
String str = client->Get(_D("https://website.com/file.txt"))->ContentAsString();
delete client;