Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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);
}
}
//---------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment