Haruyuki Mohri

毛利春幸のブログです。

Try TNetHTTPClient in C++Builder XE8

The following URL, we were referring.

www.gesource.jp
Again, it is Yamamoto Takashi san blog.

Try TNetHTTPClient in C++Builder XE8

void __fastcall TForm1::Button1Click(TObject *Sender)
{
#ifdef _WIN64
    using shareTNetHTTPClient  = std::shared_ptr<TNetHTTPClient>;
    using shareTStringStream   = std::shared_ptr<TStringStream>;
    using shareTNetHTTPRequest = std::shared_ptr<TNetHTTPRequest>;
#else /* not _WIN64 */
    typedef std::tr1::shared_ptr<TNetHTTPClient>  shareTNetHTTPClient;
    typedef std::tr1::shared_ptr<TStringStream>   shareTStringStream;
    typedef std::tr1::shared_ptr<TNetHTTPRequest> shareTNetHTTPRequest;
#endif

    DynamicArray<System::Net::Urlclient::TNameValuePair> a;
    a.Length = 1;
    a[0].Name = "User-Agent";
    a[0].Value = "My Browser mozilla/5.0";


    shareTStringStream ss(new TStringStream("", TEncoding::UTF8, true ));

    shareTNetHTTPClient http_client(new TNetHTTPClient(this) );
    shareTNetHTTPRequest http_request(new TNetHTTPRequest(this) );
    http_request->Client = &(*http_client);
    try
    {
        http_request->Get("http://www.mojeld.com", ss.get(), a);
        Memo1->Lines->Append(ss->DataString);
    }
    catch(Exception& ex)
    {
        Memo1->Lines->Append(ex.Message);
    }
}
//---------------------------------------------------------------------------

Try TNetHTTPClient in C++Builder XE8 · GitHub


Reference

System.Net.HttpClientComponent - RAD Studio API Documentation