How can I download a string from a URL in a C++Builder VCL application?

705 Views Asked by At

I want to download a string from a URL that would essentially look like this:

In C# WinForms, I know I can do this:

using System.Net;
WebClient client = new WebClient();
string str = client.DownloadString("https://website.com/file.txt");

And the string would be stored in str. I want to do exactly that in a C++ VCL application.

1

There are 1 best solutions below

0
Remy Lebeau On BEST ANSWER

There are plenty of HTTP libraries that are available for C++Builder. It even comes with 2 pre-installed:

Indy's TIdHTTP component

#include <IdHTTP.hpp>

TIdHTTP *client = new TIdHTTP();
String str = client->Get(_D("https://website.com/file.txt"));
delete client;

Embarcadero's THTTPClient component:

#include <System.Net.HttpClient.hpp>

THTTPClient *client = THTTPClient::Create();
String str = client->Get(_D("https://website.com/file.txt"))->ContentAsString();
delete client;