HTTPClient Component
Properties Methods Events Configuration Settings Errors
The HTTPClient component implements client-side functionality of HTTP and HTTPS protocols.
Syntax
TsbxHTTPClient
Remarks
HTTPClient provides means of exchanging HTTP messages with HTTP servers. Both plain (HTTP) and secure (HTTPS) connection types are supported.
Features supported
- All standard request types (GET, POST, PUT etc.), plus custom VERBs
- TLS 1.2 and 1.3 (and earlier versions for older servers)
- Strong client and server authentication on TLS and HTTP levels
- Flexible custom header adjustment
- A variety of proxy server types
Configuring the component
HTTPClient is very easy to configure. In some cases, like in the example given
below, you do not need any special tuneups whatsoever:
client.Get("http://www.mywebserver.com/"); if (client.StatusCode == 200) { string response = client.OutputString; }You may need to adjust the component settings if you plan to connect to endpoints secured with TLS. By default, HTTPClient relies on the system settings when validating server certificates. If you would prefer to ignore the system trust and implement customized chain validation procedures - such as certificate pinning - in your code instead, set TLSSettings.AutoValidateCertificates to false, and subscribe to CertificateValidate event. This event will fire whenever a server certificate validation needs to be performed.
Use ClientChain collection to provide your certificates for client authentication. Make sure the provided certificate contains a private key; otherwise it will be unable to authenticate.
To provide custom HTTP headers, subscribe to HeadersPrepared event. HTTPClient fires this event right before sending the request out to the server, giving you an opportunity to alter the headers or add your own. The list of headers can be accessed via the RequestHeaders collection. Note: the headers can only be modified from the HeadersPrepared event handler. Setting them earlier or later in your code won't provide the expected effect.
Having set up the component, use the appropriate variant of the request method (such as: Get, GetBytes, or GetFile) to obtain the response in the desired format (string, memory buffer, or file).
Property List
The following is the full list of the properties of the component with short descriptions. Click on the links for further details.
BlockedCertificates | The certificates that must be rejected as trust anchors. |
ClientChain | The TLS client certificate chain. |
ConnectionInfo | Returns the details of the underlying network connection. |
CustomRequest | Specifies a custom request verb. |
DynamicData | Takes a piece of data to be sent to the server within a dynamic POST or PUT request. |
ExternalCrypto | Provides access to external signing and DC parameters. |
KeepAlivePolicy | Defines the keep-alive handling policy. |
KnownCertificates | Additional certificates for chain validation. |
KnownCRLs | Additional CRLs for chain validation. |
KnownOCSPs | Additional OCSP responses for chain validation. |
OutputBytes | Contains the response content. |
OutputString | Contains the response content. |
Proxy | The proxy server settings. |
ReasonPhrase | Contains the Reason Phrase element of the server's response. |
RequestHeaders | Contains HTTP request headers. |
RequestParameters | Provides access to common HTTP request properties. |
ResponseHeaders | Contains the HTTP server's response headers. |
ResponseParameters | Contains the HTTP server's response parameters. |
ServerChain | The TLS server's certificate chain. |
SocketSettings | Manages network connection settings. |
StatusCode | Contains the Status Code element of the server's response. |
TLSSettings | Manages TLS layer settings. |
TrustedCertificates | A list of trusted certificates for chain validation. |
UseDigestAuth | Enables or disables the HTTP Digest authentication. |
UseNTLMAuth | Enables or disables NTLM authentication. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
Config | Sets or retrieves a configuration setting. |
Delete | Sends a DELETE request to the server. |
Get | Sends a GET request to the server. |
GetBytes | Sends a GET request to the server and returns the output. |
GetFile | Sends a GET request to the server and saves the output to a file. |
GetStream | Sends a GET request to the server and saves the output in a stream. |
Head | Sends a HEAD request to the server. |
Options | Sends an OPTIONS request to the server. |
Post | Sends a POST request to the server. |
PostBytes | Sends a POST request to the server. |
PostFile | Sends a file to the server using a POST request. |
PostStream | Sends a POST request to the server. |
PostWebForm | Posts a web form data to the server. |
Put | Sends a PUT request to the server. |
PutBytes | Sends a PUT request to the server. |
PutFile | Sends a file to the server using a PUT request. |
PutStream | Sends a PUT request to the server. |
Trace | Sends a TRACE request to the server. |
Event List
The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.
CertificateValidate | Fires when the server's TLS certificate has to be validated. |
Cookie | Fired to report a received cookie. |
DocumentBegin | Marks the start of the incoming HTML document or file. |
DocumentEnd | Marks the successful receipt of the incoming HTML document or file. |
DynamicDataNeeded | Requests a portion of data to be uploaded from the application. |
Error | Information about errors during data delivery. |
ExternalSign | Handles remote or external signing initiated by the SignExternal method or other source. |
HeadersPrepared | Fires when the request headers have been formed and are about to be sent to the server. |
HeadersReceived | Fires when the HTTP response headers have just been received from the server. |
Notification | This event notifies the application about an underlying control flow event. |
Progress | Fires periodically during the data transfer. |
Redirection | Fires when the server suggests a redirect. |
Configuration Settings
The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.
CacheStreamOutput | Tells the component whether to cache stream- and file-bound responses in the component. |
ForceNTLMAuth | Activates and enforces NTLM authentication. |
IgnoreSystemTrust | Whether trusted Windows Certificate Stores should be treated as trusted. |
IgnoreUnknownTransferEncodings | All incoming responses with unknown transfer encodings are ignored if this property is true. |
MaxRedirections | The maximum number of HTTP redirects. |
PersistentAuthHeader | Whether to resend NTLM negotiation on every request. |
RequestCompressionGZip | Ask server to use GZip compression. |
RequestCompressionLevel | Ask server to use the specified compression level. |
SendBufferSize | Size of send buffer in bytes. |
SuppressRedirectionContent | Whether to suppress the redirection content. |
TempPath | Path for storing temporary files. |
TolerateMinorChainIssues | Whether to tolerate minor chain issues. |
Use100Continue | Whether to use 100-continue for POST and PUT commands. |
UseCompression | Whether to use GZip compression. |
UseMicrosoftCTL | Enables or disables automatic use of Microsoft online certificate trust list. |
UseSystemCertificates | Enables or disables the use of the system certificates. |
CheckKeyIntegrityBeforeUse | Enables or disable private key integrity check before use. |
CookieCaching | Specifies whether a cookie cache should be used for HTTP(S) transports. |
Cookies | Gets or sets local cookies for the component (supported for HTTPClient, RESTClient and SOAPClient only). |
DefDeriveKeyIterations | Specifies the default key derivation algorithm iteration count. |
EnableClientSideSSLFFDHE | Enables or disables finite field DHE key exchange support in TLS clients. |
GlobalCookies | Gets or sets global cookies for all the HTTP transports. |
HttpUserAgent | Specifies the user agent name to be used by all HTTP clients. |
LogDestination | Specifies the debug log destination. |
LogDetails | Specifies the debug log details to dump. |
LogFile | Specifies the debug log filename. |
LogFilters | Specifies the debug log filters. |
LogFlushMode | Specifies the log flush mode. |
LogLevel | Specifies the debug log level. |
LogMaxEventCount | Specifies the maximum number of events to cache before further action is taken. |
LogRotationMode | Specifies the log rotation mode. |
MaxASN1BufferLength | Specifies the maximal allowed length for ASN.1 primitive tag data. |
MaxASN1TreeDepth | Specifies the maximal depth for processed ASN.1 trees. |
OCSPHashAlgorithm | Specifies the hash algorithm to be used to identify certificates in OCSP requests. |
UseOwnDNSResolver | Specifies whether the client components should use own DNS resolver. |
UseSharedSystemStorages | Specifies whether the validation engine should use a global per-process copy of the system certificate stores. |
UseSystemOAEPAndPSS | Enforces or disables the use of system-driven RSA OAEP and PSS computations. |
UseSystemRandom | Enables or disables the use of the OS PRNG. |