# UnityWebRequest

> Provides methods to communicate with web servers.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine.Networking](/engine/6000.7/script-reference/unityengine/networking.md)
* **Assembly:** UnityEngine.UnityWebRequestModule
* **Implements:** [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

```csharp
public class UnityWebRequest : IDisposable
```

## Remarks

`UnityWebRequest` handles the flow of HTTP communication with web servers. To post-process downloaded data and pre-process uploaded data, use [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) and [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md) respectively.

`UnityWebRequest` includes static utility functions that return `UnityWebRequest` instances configured for common use cases. For example:

* [UnityWebRequest.Get](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/get.md)

* [UnityWebRequest.Post](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/post.md)

* [UnityWebRequest.Put](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/put.md)

To send a web request from a `UnityWebRequest` instance, call [UnityWebRequest.SendWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/sendwebrequest.md). After the `UnityWebRequest` begins to communicate with a remote server, you can't change any of the properties in that `UnityWebRequest` instance. HTTPS is supported and the server certificate is validated against the root certificate store available on the system the app runs on. Validation can be disabled (for example, for development server using self-signed certificate) or changed to custom handling by assigning the [\_certificateHandler](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/certificatehandler.md) property.

Depending on the platform your application runs on, `UnityWebRequest` either sets the [User-Agent header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) itself or leaves it for the operating system to set. `UnityWebRequest` sets the `User-Agent` header for all platforms except iOS, Xbox platforms, and WebGL.

**Note**: If the device that the application runs on uses proxy settings, `UnityWebRequest` applies the proxy settings after the application sends the request. **Note**: `UnityWebRequest` does not support WPAD PAC configuration with multiple proxy failover chain for the platforms it is supported. In case such configuration is used, `UnityWebRequest` will use the first proxy in the chain, and will not use other failover proxy in the chain in case of a request failure.

## Examples

```csharp
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class MyBehaviour : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(GetText());
    }

    IEnumerator GetText()
    {
        UnityWebRequest www = UnityWebRequest.Get("https://www.my-server.com");
        yield return www.SendWebRequest();

        if (www.result != UnityWebRequest.Result.Success)
        {
            Debug.Log(www.error);
        }
        else
        {
            // Show results as text
            Debug.Log(www.downloadHandler.text);

            // Or retrieve results as binary data
            byte[] results = www.downloadHandler.data;
        }
    }
}
```

## Static Fields

| Value                                                                                                        | Description                                                                |
| ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
| [kHttpVerbCREATE](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/khttpverbcreate.md) | The string "CREATE", commonly used as the verb for an HTTP CREATE request. |
| [kHttpVerbDELETE](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/khttpverbdelete.md) | The string "DELETE", commonly used as the verb for an HTTP DELETE request. |
| [kHttpVerbGET](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/khttpverbget.md)       | The string "GET", commonly used as the verb for an HTTP GET request.       |
| [kHttpVerbHEAD](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/khttpverbhead.md)     | The string "HEAD", commonly used as the verb for an HTTP HEAD request.     |
| [kHttpVerbPOST](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/khttpverbpost.md)     | The string "POST", commonly used as the verb for an HTTP POST request.     |
| [kHttpVerbPUT](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/khttpverbput.md)       | The string "PUT", commonly used as the verb for an HTTP PUT request.       |

## Constructors

| Constructor                                                                                                                                                                                                                                                               | Description                                                                                                                                                                                                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [UnityWebRequest()](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/ctor.md#unitywebrequest\(\))                                                                                                                                                   | Creates a UnityWebRequest with the default options and no attached [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) or [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md). Default method is `GET`. |
| [UnityWebRequest(System.String)](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/ctor.md#unitywebrequest\(string\))                                                                                                                                | Creates a UnityWebRequest with the default options and no attached [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) or [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md). Default method is `GET`. |
| [UnityWebRequest(System.String,System.String)](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/ctor.md#unitywebrequest\(string-string\))                                                                                                           | Creates a UnityWebRequest with the default options and no attached [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) or [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md). Default method is `GET`. |
| [UnityWebRequest(System.String,System.String,UnityEngine.Networking.DownloadHandler,UnityEngine.Networking.UploadHandler)](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/ctor.md#unitywebrequest\(string-string-downloadhandler-uploadhandler\)) | Creates a UnityWebRequest with the default options and no attached [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) or [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md). Default method is `GET`. |
| [UnityWebRequest(System.Uri)](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/ctor.md#unitywebrequest\(uri\))                                                                                                                                      | Creates a UnityWebRequest with the default options and no attached [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) or [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md). Default method is `GET`. |
| [UnityWebRequest(System.Uri,System.String)](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/ctor.md#unitywebrequest\(uri-string\))                                                                                                                 | Creates a UnityWebRequest with the default options and no attached [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) or [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md). Default method is `GET`. |
| [UnityWebRequest(System.Uri,System.String,UnityEngine.Networking.DownloadHandler,UnityEngine.Networking.UploadHandler)](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/ctor.md#unitywebrequest\(uri-string-downloadhandler-uploadhandler\))       | Creates a UnityWebRequest with the default options and no attached [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) or [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md). Default method is `GET`. |

## Properties

| Property                                                                                                                                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| -------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [certificateHandler](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/certificatehandler.md)                                 | Holds a reference to a [CertificateHandler](/engine/6000.7/script-reference/unityengine/networking/certificatehandler.md) object, which manages certificate validation for this [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md).                                                                                                                                                                                                                                |
| [disposeCertificateHandlerOnDispose](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/disposecertificatehandlerondispose.md) | If true, any [CertificateHandler](/engine/6000.7/script-reference/unityengine/networking/certificatehandler.md) attached to this [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md) will have [CertificateHandler.Dispose](/engine/6000.7/script-reference/unityengine/networking/certificatehandler/dispose.md) called automatically when [UnityWebRequest.Dispose](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/dispose.md) is called. |
| [disposeDownloadHandlerOnDispose](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/disposedownloadhandlerondispose.md)       | If true, any [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) attached to this [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md) will have [DownloadHandler.Dispose()](/engine/6000.7/script-reference/unityengine/networking/downloadhandler/dispose.md) called automatically when [UnityWebRequest.Dispose](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/dispose.md) is called.           |
| [disposeUploadHandlerOnDispose](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/disposeuploadhandlerondispose.md)           | If true, any [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md) attached to this [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md) will have [UploadHandler.Dispose()](/engine/6000.7/script-reference/unityengine/networking/uploadhandler/dispose.md) called automatically when [UnityWebRequest.Dispose](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/dispose.md) is called.                   |
| [downloadedBytes](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/downloadedbytes.md)                                       | Returns the number of bytes of body data the system has downloaded from the remote server. (Read Only)                                                                                                                                                                                                                                                                                                                                                                                                       |
| [downloadHandler](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/downloadhandler.md)                                       | Holds a reference to a [DownloadHandler](/engine/6000.7/script-reference/unityengine/networking/downloadhandler.md) object, which manages body data received from the remote server by this [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md).                                                                                                                                                                                                                    |
| [downloadProgress](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/downloadprogress.md)                                     | Returns a floating-point value between 0.0 and 1.0, indicating the progress of downloading body data from the server. (Read Only)                                                                                                                                                                                                                                                                                                                                                                            |
| [error](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/error.md)                                                           | A human-readable string describing any system errors encountered by this [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md) object while handling HTTP requests or responses. The default value is `null`. (Read Only)                                                                                                                                                                                                                                             |
| [httpForcedVersion](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/httpforcedversion.md)                                   | Force the version of HTTP used when making web requests with [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md).                                                                                                                                                                                                                                                                                                                                                   |
| [isDone](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/isdone.md)                                                         | Returns `true` after the [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md) has finished communicating with the remote server. (Read Only)                                                                                                                                                                                                                                                                                                                         |
| [isModifiable](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/ismodifiable.md)                                             | Returns `true` while a [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md)’s configuration properties can be altered. (Read Only)                                                                                                                                                                                                                                                                                                                                   |
| [method](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/method.md)                                                         | Defines the HTTP verb used by this [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md), such as `GET` or `POST`.                                                                                                                                                                                                                                                                                                                                                    |
| [redirectLimit](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/redirectlimit.md)                                           | Indicates the number of redirects that this [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md) follows before halting with a `Redirect Limit Exceeded` system error.                                                                                                                                                                                                                                                                                               |
| [responseCode](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/responsecode.md)                                             | The numeric HTTP response code returned by the server, such as `200`, `404` or `500`. (Read Only)                                                                                                                                                                                                                                                                                                                                                                                                            |
| [result](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/result-1.md)                                                       | The result of this UnityWebRequest.                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| [timeout](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/timeout.md)                                                       | The number of seconds after which UnityWebRequest attempts to abort the request if no response is received.                                                                                                                                                                                                                                                                                                                                                                                                  |
| [uploadedBytes](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/uploadedbytes.md)                                           | Returns the number of bytes of body data the system has uploaded to the remote server. (Read Only)                                                                                                                                                                                                                                                                                                                                                                                                           |
| [uploadHandler](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/uploadhandler.md)                                           | Holds a reference to the [UploadHandler](/engine/6000.7/script-reference/unityengine/networking/uploadhandler.md) object which manages body data to be uploaded to the remote server.                                                                                                                                                                                                                                                                                                                        |
| [uploadProgress](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/uploadprogress.md)                                         | Returns a floating-point value between 0.0 and 1.0, indicating the progress of uploading body data to the server.                                                                                                                                                                                                                                                                                                                                                                                            |
| [uri](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/uri.md)                                                               | Defines the target URI for the [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md) to communicate with.                                                                                                                                                                                                                                                                                                                                                             |
| [url](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/url.md)                                                               | Defines the target URL for the [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md) to communicate with.                                                                                                                                                                                                                                                                                                                                                             |
| [useHttpContinue](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/usehttpcontinue.md)                                       | Determines whether this UnityWebRequest will include `Expect: 100-Continue` in its outgoing request headers. (Default: `true`).                                                                                                                                                                                                                                                                                                                                                                              |

## Static Properties

| Property                                                                                                                         | Description                                               |
| -------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| [enableProfilerBodyCapture](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/enableprofilerbodycapture.md) | Whether the Profiler captures the bodies of web requests. |

## Methods

| Method                                                                                                               | Description                                                                                                                                                                            |
| -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Abort](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/abort.md)                             | If in progress, halts the UnityWebRequest as soon as possible.                                                                                                                         |
| [Dispose](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/dispose.md)                         | Signals that this [UnityWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest.md) is no longer being used, and should clean up any resources it is using. |
| [GetRequestHeader](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/getrequestheader.md)       | Retrieves the value of a custom request header.                                                                                                                                        |
| [GetResponseHeader](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/getresponseheader.md)     | Retrieves the value of a response header from the latest HTTP response received.                                                                                                       |
| [GetResponseHeaders](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/getresponseheaders.md)   | Retrieves a dictionary containing all the response headers received by this UnityWebRequest in the latest HTTP response.                                                               |
| [GetResponseTrailer](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/getresponsetrailer.md)   | Retrieves the value of a response trailer from the latest HTTP response received.                                                                                                      |
| [GetResponseTrailers](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/getresponsetrailers.md) | Retrieves a dictionary containing all the response trailers received by this UnityWebRequest in the latest HTTP response.                                                              |
| [SendWebRequest](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/sendwebrequest.md)           | Begin communicating with the remote server.                                                                                                                                            |
| [SetRequestHeader](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/setrequestheader.md)       | Sets an HTTP request header to a custom value.                                                                                                                                         |

## Static Methods

| Method                                                                                                                   | Description                                                                                            |
| ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ |
| [ClearCookieCache](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/clearcookiecache.md)           | Clears stored cookies from the cache.                                                                  |
| [Delete](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/delete.md)                               | Creates a UnityWebRequest configured for HTTP `DELETE`.                                                |
| [EscapeURL](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/escapeurl.md)                         | Escapes characters in a string to ensure they are URL-friendly.                                        |
| [GenerateBoundary](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/generateboundary.md)           | Generate a random 40-byte array for use as a multipart form boundary.                                  |
| [Get](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/get.md)                                     | Create a UnityWebRequest for HTTP GET.                                                                 |
| [Head](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/head.md)                                   | Creates a UnityWebRequest configured to send a HTTP `HEAD` request.                                    |
| [Post](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/post.md)                                   | Create a UnityWebRequest configured to send form data to a server via HTTP `POST`.                     |
| [PostWwwForm](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/postwwwform.md)                     | Creates a UnityWebRequest configured to send form data to a server via HTTP `POST`.                    |
| [Put](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/put.md)                                     | Creates a UnityWebRequest configured to upload raw data to a remote server via HTTP PUT.               |
| [SerializeFormSections](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/serializeformsections.md) | Converts a List of IMultipartFormSection objects into a byte array containing raw multipart form data. |
| [SerializeSimpleForm](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/serializesimpleform.md)     | Serialize a dictionary of strings into a byte array containing URL-encoded UTF8 characters.            |
| [UnEscapeURL](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/unescapeurl.md)                     | Converts URL-friendly escape sequences back to normal text.                                            |

## Enums

| Enum                                                                                                       | Description                                                          |
| ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [UnityWebRequest.Result](/engine/6000.7/script-reference/unityengine/networking/unitywebrequest/result.md) | Defines codes describing the possible outcomes of a UnityWebRequest. |
