Class AsyncHttpRequestor
Class for performing asynchronous HTTP requests. This class may be used to perform GET, POST, PUT and DELETE requests. It may also be used when a persistent connection to a server is desired.
Implements
Inherited Members
Namespace: HttpUtils
Assembly: Ng911Lib.dll
Syntax
public class AsyncHttpRequestor : IDisposable
Constructors
| Edit this page View SourceAsyncHttpRequestor(X509Certificate2, int, string)
Constructs a new AsyncHttpRequestor object. Once this constructor is called, the object is ready to start making requests.
Declaration
public AsyncHttpRequestor(X509Certificate2 clientCertificate, int TimeoutMs = 1000, string strAcceptHeader = null)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate2 | clientCertificate | Client X.509 certificate. May be null in applications where mutual authentication is not required. |
int | TimeoutMs | Sets the request timeout in milliseconds. Defaults to 1000 ms. |
string | strAcceptHeader | Value to add to the default headers. For example: application/json. May contain a comma separated list of MIME types. May be null. |
Properties
| Edit this page View SourceAcceptAllServerCertificates
If set to true, the all server certificates will be accepted. If false the server authentication is tested. The default is true.
Declaration
public bool AcceptAllServerCertificates { get; set; }
Property Value
Type | Description |
---|---|
bool |
Methods
| Edit this page View SourceDispose()
Disposes the HttpClient object used by this class. Do not call any other methods or properties after calling this method.
Declaration
public void Dispose()
DoRequestAsync(HttpMethodEnum, string, string, string, bool)
Sends the HTTP request asynchronously and waits for a response.
Declaration
public Task<HttpResults> DoRequestAsync(HttpMethodEnum Method, string strUrl, string strContentType, string strContents, bool ExpectRespBody)
Parameters
Type | Name | Description |
---|---|---|
HttpMethodEnum | Method | HTTP method to use. |
string | strUrl | URL of the request. |
string | strContentType | Specifies the Content-Type header to send if the request message will contain a body. For example: application/json. May be null if strContents is null. |
string | strContents | Contains the request body. May be null if there is no body to send. |
bool | ExpectRespBody | If true, then a response containing a message body is expected and this method will read it. If false, then the response is not expected to contain a message body. |
Returns
Type | Description |
---|---|
Task<HttpResults> | Returns a HttpResults object. This method always returns a value, even if an exception occurred. |
GetStringResponseAsync(string)
Sends a GET request and returns a string response asynchronously.
Declaration
public Task<string> GetStringResponseAsync(string strUrl)
Parameters
Type | Name | Description |
---|---|---|
string | strUrl | URL to request. |
Returns
Type | Description |
---|---|
Task<string> | Returns a string from the response body if the server returned a 200 OK response and a string in the response body. Returns null if an error occurred. |