Http |
public class HttpClient : Client
The HttpClient type exposes the following members.
| Name | Description | |
|---|---|---|
| HttpClient | Creates a new instance of the HttpClient class. |
| Name | Description | |
|---|---|---|
| Accept | Gets or sets content types that are acceptable for the response. The default value is "text/html, image/gif, image/jpeg, image/png, */*". | |
| AllowAutoRedirect | Gets or sets a value that indicates whether the request should follow redirection responses (HTTP codes from 300 to 399). Default Value: true | |
| Binding | Obsolete. Obsolete - Please use BindingV4 and BindingV6 instead. (Inherited from Client) | |
| BindingV4 |
Gets the binding which provides properties and methods such as address family, IPv4 address, port number etc for client to connect to the host network.
(Inherited from Client) | |
| BindingV6 |
Gets the binding which provides properties and methods such as address family, IPv6 address, port number etc for client to connect to the host network.
(Inherited from Client) | |
| ConnectionClass |
Use the ConnectionClass property to specify an alternative Connection class to be used for out coming data connections.
Existing connections are not affected by changing the property.
(Inherited from Client) | |
| ConnectionPool |
Get or set the Connection Pool for this Client Instance.
(Inherited from Client) | |
| CustomConnectionPool | Gets or sets the custom connection pool. This property is inherited from the Client class. | |
| DnsResolveType |
Determines if the specified HostName should be looked up only:
Once per application run (if you establish multiple connections to the server, the subsequent connections will use the cached IPAddress) or
Always, for each connect (the Hostname will be resolved again for each subsequent connect).
You'll usually only change this setting off the default (Once) if you anticipate the IPAddress of the target host to change frequently.
(Inherited from Client) | |
| EnableNagle |
Set the property value to true to enable the Nagle algorithm for send coalescing.
(Inherited from Client) | |
| HostAddress |
Gets or sets a Client Host IP Address as a string.
(Inherited from Client) | |
| HostName |
The server host name or IP address that you intend the client to connect to.
(Inherited from Client) | |
| KeepAlive | Controls whether to use HTTP Keep-Alive to keep the connection alive between requests. If enabled (true) , once a request is made and a connection is established, this connection is kept open and used for future requests. If disabled, the connection is closed, and a new connection is created for future requests. | |
| MaximumAutomaticRedirections | Gets or sets the maximum number of redirects that the request follows. Default Value: 20 | |
| Password | Password that will be inserted into the Authorization HTTP header in the request to the server. | |
| Port |
The server Port that you intend the client to connect to.
If you do not assign a port number on this property, the port number in the parsed URL will be used. If a port number is assigned in the parsed URL, it will take precedence over this property. (Inherited from Client) | |
| ProcessBusy | If using commands with callbacks, check this busy flag before using another command (Dispatch, Get, Post, etc.) | |
| Timeout | Gets or sets the maximum amount of time (in seconds) that a client will wait for a server response within a single request. The default value is 60 seconds (1 minute). The timeout handling can be activated via the TimeoutEnabled property. | |
| TimeoutEnabled | This property controls whether the request operation will do an automatic timeout checking. If timeout handling is turned on (i.e. this property is set to true) and a request takes longer than Timeout, it will be terminated. | |
| Url | Gets or sets the URL of the remote server. | |
| UseConnectionPooling | Enables or disables connection pooling. | |
| UserAgent | Gets or sets the identifier of the software being used to retrieve data via the URL. Some custom HTTP servers check this HTTP header to provide content optimized for particular HTTP browsers. | |
| UserName | Name that will be inserted into the Authorization HTTP header in the request to the server. | |
| UserObject | Gets the last user specified Object for the Async operations on this HTTP Client instance. The return value will evaluate to null if Async operations with the object parameter are not utilized. | |
| Verbose | Set Logging to Verbose on/off | |
| Version | Gets or sets the version identifier of the UserAgent. Can be used to mimic particular browsers like Internet Explorer 6.0 |
| Name | Description | |
|---|---|---|
| Abort | Closes the currently open connection (if present). | |
| BeginGetRequestStream | Begins an asynchronous request for a Stream object to use to write data. | |
| BeginGetResponseStream | Begins an asynchronous response for a Stream object to use to read data. | |
| Connect |
Connect the client to a remote network host.
(Inherited from Client) | |
| Connect(String, Int32) |
Connect to the host address at the specified port.
(Inherited from Client) | |
| ConnectNew |
Overloaded. Opens and returns new connection with specified host and port.
(Inherited from Client) | |
| Dispatch | One of the core methods of the HttpClient class. This method uses the HttpClientRequest class to send messages to the server and the HttpClientResponse to receive server answers. Uses the TryDispatch method to send data and raises an HttpException exception if any errors occurs. | |
| DispatchAsync | Asynchronously dispatch a request and return a response to the specified callback function | |
| DispatchAsyncEx | Asynchronously dispatch a request and return a response to the specified callback function | |
| DispatchBytesAsync | Asynchronously launches the request that returns a byte array | |
| DispatchBytesAsyncEx | Asynchronously launches the request that returns a byte array | |
| DispatchStringAsync | Asynchronously launches the request that returns a string | |
| DispatchStringAsyncEx | Asynchronously launches the request that returns a string | |
| Dispose |
Disposes the Client Connection.
(Inherited from Client) | |
| Dispose(Boolean) |
Disposes of the current instance and releases all resources used by it.
(Overrides ClientDispose(Boolean)) | |
| EndGetRequestStream | Supply the stream interface | |
| EndGetResponseStream | Ends an asynchronous request to an Internet resource | |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) | |
| FgetFile | Gets the file from the server and writes the data to lpath | |
| Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) | |
| FpostFile | Posts the file data to the server from the local machine | |
| FputFile | Puts the file data to the server from the local machine | |
| Get(String) | Retrieves an HTTP document (as a string) from the provided URL using the GET HTTP command. | |
| Get(String, Encoding) | Retrieves an HTTP document (as a string) in the specified encoding from the provided URL using the GET HTTP command. | |
| GetAsync(String, HTTPClientStringCallback) | Asynchronously retrieves an HTTP document from the provided URL using the GET HTTP command. | |
| GetAsync(String, Encoding, HTTPClientStringCallback) | Asynchronously retrieves an HTTP document using a callback in the specified encoding from the provided URL using the GET HTTP command. | |
| GetAsyncEx(String, HTTPClientStringCallbackEx, Object) | Asynchronously retrieves an HTTP document from the provided URL using the GET HTTP command. | |
| GetAsyncEx(String, Encoding, HTTPClientStringCallbackEx, Object) | Asynchronously retrieves an HTTP document using a callback in the specified encoding from the provided URL using the GET HTTP command. | |
| GetBytes | Retrieves binary data from the provided URL. | |
| GetBytesAsync | Asynchronously retrieves binary data from the provided URL using a callback. | |
| GetBytesAsyncEx | Asynchronously retrieves binary data from the provided URL using a callback. | |
| GetHashCode | Serves as the default hash function. (Inherited from Object) | |
| GetHttpConnection | This method is used internally to acquire (either create or retrieve from the pool) an HTTP connection with the provided parameters. | |
| GetResponse | This method is used internally by all other Get* methods of this class. It creates and sends a GET HTTP request to the server and returns a response. | |
| GetResponseAsync | Asynchronously creates and sends a GET HTTP request to the server using the callback. A Response is returned. | |
| GetResponseAsyncEx | Asynchronously creates and sends a GET HTTP request to the server using the callback. A Response is returned. | |
| GetType | Gets the Type of the current instance. (Inherited from Object) | |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) | |
| NewConnection |
Creates a New Client Connection with the specified binding.
(Inherited from Client) | |
| Post(String, Stream) | Retrieves an HTTP document (as a string) from the provided Url using the POST HTTP command. | |
| Post(String, Byte) | Retrieves an HTTP document (as a string) from the provided URL using the POST HTTP command. | |
| PostAsync(String, Stream, HTTPClientResponseCallback) | Asynchronously retrieves an HTTP document (as a string) from the provided Url using the POST HTTP command. | |
| PostAsync(String, Byte, HTTPClientStringCallback) | Asynchronously retrieves an HTTP document (as a string) from the provided Url using the POST HTTP command. | |
| PostAsync(String, Byte, HTTPClientStringCallbackEx, Object) | Asynchronously retrieves an HTTP document (as a string) from the provided Url using the POST HTTP command. | |
| PostAsyncEx | Asynchronously retrieves an HTTP document (as a string) from the provided Url using the POST HTTP command. | |
| ReleaseConnection |
Releases the Connection for the specified connection in the Connection Pool.
(Inherited from Client) | |
| RequestDone | Request is done being processed. | |
| ResolveHostName |
Resolves the host name.
(Inherited from Client) | |
| ResolveHostNameIfNeeded |
Determines whether it is necessary to resolve the host name based on the Host Address and DNS resolve type, and then resolves the host name accordingly.
(Inherited from Client) | |
| ToString | Returns a string that represents the current object. (Inherited from Object) | |
| TriggerOnResolvedHostName |
Trigger the OnResolvedHostName.
(Inherited from Client) | |
| TriggerOnResolveHostName |
Triggers the Resolve
(Inherited from Client) |
| Name | Description | |
|---|---|---|
| OnResolvedHostName |
This event is fired after the hostname has been successfully resolved.
(Inherited from Client) | |
| OnResolveHostName |
This event is fired before the Client attempts to resolve the specified HostName to an IP address.
It provides you with an option to perform the resolution yourself, obtain the IP address from an internal cache you're maintaining, or do some other processing (such as for example changing the hostname to look up).
(Inherited from Client) |
// Send a DELETE request to the specified URL public void SendDelete(string urlString) { try { HttpClient client = new HttpClient(); HttpClientRequest req = new HttpClientRequest(); UrlParser url = new UrlParser(urlString); req.Url = url; req.RequestType = RequestType.Delete; HttpClientResponse res = client.Dispatch(req); if (res.Code == 204) // Expecting a "Not Found" response to show that the DELETE succeeded { CrestronConsole.PrintLine("DELETE request succeeded"); } else { CrestronConsole.PrintLine("DELETE request returned unexpected response code: {0}", res.Code); } res.Dispose(); client.Dispose(); } catch (Exception e) { CrestronConsole.PrintLine("Error in SendDelete(): " + e); } }