0

我想从一个基本上看起来像这样的 URL 下载一个字符串:

在 C# WinForms 中,我知道我可以这样做:

使用 System.Net;
WebClient 客户端 = 新 WebClient();
string str = client.DownloadString("https://website.com/file.txt");

字符串将存储在str. 我想在 C++ VCL 应用程序中做到这一点。

4

1 回答 1

2

有大量可用于 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;
于 2020-06-23T00:34:29.060 回答