handles the flow of HTTP communication with web servers. To post-process downloaded data and pre-process uploaded data, use DownloadHandler and UploadHandler respectively.
UnityWebRequest
includes static utility functions that return
UnityWebRequest
instances configured for common use cases. For example:
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 UnityWebRequest.certificateHandler property.
Depending on the platform your application runs on,
UnityWebRequest
either sets the User-Agent header 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
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; } }}
A human-readable string describing any system errors encountered by this UnityWebRequest object while handling HTTP requests or responses. The default value is