Version: 2019.1
NetworkServerSimple
Operaciones comunes: utilizando HLAPI

UnityWebRequest

Note: UNet is deprecated, and will be removed from Unity in the future. A new system is under development. For more information and next steps see this blog post and the FAQ.

UnityWebRequest 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 web browser 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.

El sistema consiste de dos capas:

  • 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

Plataformas soportadas

El sistema de UnityWebRequest soporta la mayoría de plataformas de Unity:

  • All versions of the Editor and Standalone players
  • WebGL
  • Mobile platforms: iOS, Android
  • Plataforma Universal Windows
  • PS4 and PSVita
  • XboxOne
  • Nintendo Switch

Arquitectura

El ecosistema de UnityWebRequest rompe una transacción HTTP a tres operaciones distintas:

  • Proporcionando datos al servidor
  • Recibiendo datos del servidor
  • Un flujo de control HTTP (por ejemplo, re-direccionamiento, manejo de errores)

Para proporcionar una mejor interfaz para usuarios avanzados, estas operaciones son gobernadas por sus propios objetos:

  • Un objeto UploadHandler maneja la transmisión de datos al servidor
  • Un objeto DownloadHandler maneja la recepción, buffering y post-procesamiento de datos recibidos del servidor
  • Un objeto UnityWebRequest maneja los otros dos objetos, y también maneja el flujo de control HTTP. Este objeto es dónde los encabezados personalizados y URLs se definen, y dónde la información de error y re-direccionamiento se almacena.

Para cualquier transacción HTTP dada, el flujo de código normal es:

  • Cree un objeto Web Request
  • Configure el objeto Web Request
    • Configure encabezados personalizados
    • Set HTTP verb (such as GET, POST, HEAD - custom verbs are permitted on all platforms except for Android)
    • Configure URL
  • (Optional) Create an Upload Handler and attach it to the Web Request
    • Proporcione datos para ser subidos
    • Proporcione el HTTP form en ser subido
  • (Optional) Create a Download Handler and attach it to the Web Request
  • Envie el Web Request
    • If inside a coroutine, you may Yield the result of the Send() call to wait for the request to complete
  • (Opcional) Leer datos recibidos del Download Handler
  • (Opcional) Leer información de error, código del estatus HTTP y encabezados de respuesta del objeto UnityWebRequest

• 2017–05–16 Page amended with no editorial review

NetworkServerSimple
Operaciones comunes: utilizando HLAPI