Legacy Documentation: Version 5.3
Networking Tips for Mobile devices.
Networking Reference

UnityWebRequest

UnityWebRequest is a replacement for Unity’s original WWW object. It provides a modular system for composing HTTP requests and handling HTTP responses. The primary goal of the UnityWebRequest system is to allow Unity games to interact with modern Web back-ends. It also supports high-demand features such as chunked HTTP requests, streaming POST/PUT operations, and full control over HTTP headers and verbs.

For end-users who only employ common WWW use cases, transitioning to the new system should be almost completely a find-and-replace process.

The system consists of two layers:

  • A High-Level API (HLAPI) wraps the Low-Level API and provides a convenient interface for performing common operations
  • A Low-Level API (LLAPI) provides maximum flexibility for more advanced users

To learn more about these layers, see the the following pages contained in this section:

Supported platforms

The UnityWebRequest system supports most Unity platforms:

  • All versions of the Editor & Standalone players
  • WebGL
  • Mobile Platforms: iOS, Android, Windows Phone 8
  • Windows Store Apps
  • PS3
  • Xbox 360

Architecture

The UnityWebRequest ecosystem breaks down an HTTP transaction into three distinct operations:

  • Supplying data to the server
  • Receiving data from the server
  • HTTP flow control (for example, redirects and error handling)

To provide a better interface for advanced users, these operations are each governed by their own objects:

  • An UploadHandler object handles transmission of data to the server
  • A DownloadHandler object handles receipt, buffering and postprocessing of data received from the server
  • A UnityWebRequest object manages the other two objects, and also handles HTTP flow control. This object is where custom headers and URLs are defined, and where error and redirect information is stored.

For any HTTP transaction, the normal code flow is:

  • Create a Web Request object
  • Configure the Web Request object
    • Set custom headers
    • Set HTTP verb (such as GET, POST, HEAD. Custom verbs are permitted.)
    • Set URL
  • (Optional) Create an Upload Handler & attach it to the Web Request
    • Provide data to be uploaded
    • Provide HTTP form to be uploaded
  • (Optional) Create a Download Handler & attach it to the Web Request
  • Send the Web Request
    • If inside a coroutine, you may Yield the result of the Send() call to wait for the request to complete.
  • (Optional) Read received data from the Download Handler
  • (Optional) Read error information, HTTP status code and response headers from the UnityWebRequest object
Networking Tips for Mobile devices.
Networking Reference