HTTPRequest¶
Represents an HTTP request that allows you to send HTTP requests to remote servers and receive responses asynchronously.
Remarks:
- Asynchronous HTTP requests: Utilize a Task-based API for performing HTTP requests asynchronously.
- Unity coroutine support: Seamlessly integrate with Unity's coroutine system for coroutine-based request handling.
- HTTP method support: Support for various HTTP methods including GET, POST, PUT, DELETE, and more.
- Compression and decompression: Automatic request and response compression and decompression for efficient data transfer.
- Timing information: Collect detailed timing information about the request for performance analysis.
- Upload and download support: Support for uploading and downloading files with progress tracking.
- Customizable: Extensive options for customizing request headers, handling cookies, and more.
- Redirection handling: Automatic handling of request redirections for a seamless experience.
- Proxy server support: Ability to route requests through proxy servers for enhanced privacy and security.
- Authentication: Automatic authentication handling using authenticators for secure communication.
- Cancellation support: Ability to cancel requests to prevent further processing and release resources.
Fields:¶
String[] HTTPRequest.MethodNames
¶
- Cached uppercase values to save some cpu cycles and GC alloc per request.
HTTPMethods MethodType¶
- The method that how we want to process our request the server.
Uri Uri¶
- The original request's Uri.
Uri CurrentUri¶
- If redirected it contains the RedirectUri.
HostKey CurrentHostKey¶
- A host-key that can be used to find the right host-variant for the request.
HTTPResponse Response¶
- The response received from the server. If an exception occurred during reading of the response stream or can't connect to the server, this will be null!
DownloadSettings DownloadSettings¶
- Download related options and settings.
UploadSettings UploadSettings¶
- Upload related options and settings.
TimeoutSettings TimeoutSettings¶
- Timeout settings for the request.
RetrySettings RetrySettings¶
- Retry settings for the request.
ProxySettings ProxySettings¶
- Proxy settings for the request.
RedirectSettings RedirectSettings¶
- Redirect settings for the request.
OnRequestFinishedDelegate Callback¶
- The callback function that will be called after the request is fully processed.
Boolean IsCancellationRequested¶
- Indicates if Abort is called on this request.
Action<HTTPRequest> OnCancellationRequested¶
- Action called when Abort function is invoked.
Exception Exception¶
- Stores any exception that occurs during processing of the request or response. This property if for debugging purposes as seen here!
Object Tag¶
- Any user-object that can be passed with the request.
HTTPRequestStates State¶
- Current state of this request.
TimingCollector Timing¶
- Timing information about the request.
IAuthenticator Authenticator¶
- An IAuthenticator implementation that can be used to authenticate the request. Out-of-the-box included authenticators are CredentialAuthenticator and BearerTokenAuthenticator.
Boolean WithCredentials¶
- Its value will be set to the XmlHTTPRequest's withCredentials field, required to send 3rd party cookies with the request. More details can be found here:
LoggingContext Context¶
- Logging context of the request.
Object Current¶
- IEnumerator implementation, required for Coroutine support.
Methods:¶
HTTPRequest HTTPRequest.CreateGet(String)¶
- Creates an HTTP GET request with the specified URL.
HTTPRequest HTTPRequest.CreateGet(Uri)¶
- Creates an HTTP GET request with the specified URI.
HTTPRequest HTTPRequest.CreateGet(String, OnRequestFinishedDelegate)¶
- Creates an HTTP GET request with the specified URL and registers a callback function to be called when the request is fully processed.
HTTPRequest HTTPRequest.CreateGet(Uri, OnRequestFinishedDelegate)¶
- Creates an HTTP GET request with the specified URI and registers a callback function to be called when the request is fully processed.
HTTPRequest HTTPRequest.CreatePost(String)¶
- Creates an HTTP POST request with the specified URL.
HTTPRequest HTTPRequest.CreatePost(Uri)¶
- Creates an HTTP POST request with the specified URI.
HTTPRequest HTTPRequest.CreatePost(String, OnRequestFinishedDelegate)¶
- Creates an HTTP POST request with the specified URL and registers a callback function to be called when the request is fully processed.
HTTPRequest HTTPRequest.CreatePost(Uri, OnRequestFinishedDelegate)¶
- Creates an HTTP POST request with the specified URI and registers a callback function to be called when the request is fully processed.
HTTPRequest HTTPRequest.CreatePut(String)¶
- Creates an HTTP PUT request with the specified URL.
HTTPRequest HTTPRequest.CreatePut(Uri)¶
- Creates an HTTP PUT request with the specified URI.
HTTPRequest HTTPRequest.CreatePut(String, OnRequestFinishedDelegate)¶
- Creates an HTTP PUT request with the specified URL and registers a callback function to be called when the request is fully processed.
HTTPRequest HTTPRequest.CreatePut(Uri, OnRequestFinishedDelegate)¶
- Creates an HTTP PUT request with the specified URI and registers a callback function to be called when the request is fully processed.
Void AddHeader(String, String)¶
- Adds a header-value pair to the Headers. Use it to add custom headers to the request.
Void SetHeader(String, String)¶
- For the given header name, removes any previously added values and sets the given one.
Boolean RemoveHeader(String)¶
- Removes the specified header and all of its associated values. Returns
true
, if the header found and succesfully removed.
Boolean HasHeader(String)¶
- Returns
true
if the given head name is already in theHTTPRequest.Headers
.
String GetFirstHeaderValue(String)¶
- Returns the first header or
null
for the given header name.
List<String> GetHeaderValues(String)¶
- Returns all header values for the given header or
null
.
Void RemoveHeaders()¶
- Removes all headers.
Void SetRangeHeader(Int64)¶
- Sets the Range header to download the content from the given byte position. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
Void SetRangeHeader(Int64, Int64)¶
- Sets the Range header to download the content from the given byte position to the given last position. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
HTTPRequest Send()¶
- Starts processing the request.
Void Abort()¶
- Cancels any further processing of the HTTP request.
Void Clear()¶
- Resets the request for a state where switching MethodType is possible.
Boolean MoveNext()¶
- IEnumerator implementation, required for Coroutine support.
Void Reset()¶
- IEnumerator implementation throwing NotImplementedException, required for Coroutine support.
Void Dispose()¶
- Disposes of resources used by the HTTPRequest instance.