System.Net.HttpClient.THTTPClient.Post

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function Post(const AURL: string; const ASourceFile: string; const AResponseContent: TStream = nil; const AHeaders: TNetHeaders = nil): IHTTPResponse; overload;
function Post(const AURL: string; const ASource: TStrings; const AResponseContent: TStream = nil;  const AEncoding: TEncoding = nil; const AHeaders: TNetHeaders = nil): IHTTPResponse; overload;
function Post(const AURL: string; const ASource: TStream; const AResponseContent: TStream = nil;  const AHeaders: TNetHeaders = nil): IHTTPResponse; overload;
function Post(const AURL: string; const ASource: TMultipartFormData; const AResponseContent: TStream = nil;  const AHeaders: TNetHeaders = nil): IHTTPResponse; overload;

C++

_di_IHTTPResponse __fastcall Post(const System::UnicodeString AURL, const System::UnicodeString ASourceFile, System::Classes::TStream* const AResponseContent = (System::Classes::TStream*)(0x0), const System::DynamicArray<System::Net::Urlclient::TNameValuePair> AHeaders = System::DynamicArray<System::Net::Urlclient::TNameValuePair>())/* overload */;
_di_IHTTPResponse __fastcall Post(const System::UnicodeString AURL, System::Classes::TStrings* const ASource, System::Classes::TStream* const AResponseContent = (System::Classes::TStream*)(0x0), System::Sysutils::TEncoding* const AEncoding = (System::Sysutils::TEncoding*)(0x0), const System::DynamicArray<System::Net::Urlclient::TNameValuePair> AHeaders = System::DynamicArray<System::Net::Urlclient::TNameValuePair>())/* overload */;
_di_IHTTPResponse __fastcall Post(const System::UnicodeString AURL, System::Classes::TStream* const ASource, System::Classes::TStream* const AResponseContent = (System::Classes::TStream*)(0x0), const System::DynamicArray<System::Net::Urlclient::TNameValuePair> AHeaders = System::DynamicArray<System::Net::Urlclient::TNameValuePair>())/* overload */;
_di_IHTTPResponse __fastcall Post(const System::UnicodeString AURL, System::Net::Mime::TMultipartFormData* const ASource, System::Classes::TStream* const AResponseContent = (System::Classes::TStream*)(0x0), const System::DynamicArray<System::Net::Urlclient::TNameValuePair> AHeaders = System::DynamicArray<System::Net::Urlclient::TNameValuePair>())/* overload */;

Properties

Type Visibility Source Unit Parent
function public
System.Net.HttpClient.pas
System.Net.HTTPClient.hpp
System.Net.HttpClient THTTPClient

Description

Sends an HTTP request to the specified URL with the specified data using the POST HTTP request method, waits for the server to send a response, and returns the HTTP response of the server.

To specify the data to send, do any of the following:

  • To send the content of a local file, specify the local path of that file as ASourceFile.
  • To send the content of a string list, provide your instance of TStrings as ASource, and if your strings are not encoded in UTF-8, provide an instance of TEncoding as AEncoding.
  • To send the content of a stream, provide your instance of TStream as ASource, make sure to first set TStream.Position to 0.
  • To send form data encoded as a MIME multipart message following the HTML 4 standard, provide your instance of TMultipartFormData as ASource.

If you want to receive the response data as your HTTP client downloads it from the target server, instead of waiting for your HTTP client to download the whole data, use the AResponseContent parameter to specify a stream to receive the downloaded data. Alternatively, you can wait for your HTTP client to download the whole response data, and obtain the response data as a stream from the ContentStream property of the response object that Get returns.

Regardless of whether you receive the data as it comes or wait for the whole data to be available, you can handle the OnReceiveData event to track the progress of the download of the response data.

Use AHeaders to include custom HTTP request headers in your HTTP request.

Post raises an ENetHTTPRequestException if the HTTP request reaches the maximum number of redirects.

See Also