【问题标题】:How can I download a string from a URL in a C++Builder VCL application?如何从 C++Builder VCL 应用程序中的 URL 下载字符串?
【发布时间】:2020-06-23 00:18:35
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: c++ string c++builder vcl downloadstring


    【解决方案1】:

    有大量可用于 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;
    

    【讨论】:

      猜你喜欢
      • 2023-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-10
      • 2012-01-23
      • 2015-04-09
      • 2021-10-05
      相关资源
      最近更新 更多