---
title: Unity Web 请求 API 简介
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/zh-cn/engine/6000.0/manual/scripting/object-oriented-development/web-request/intro
latest_url: https://docs.unity.com/zh-cn/engine/7000.0/manual/scripting/object-oriented-development/web-request/intro.md
generated_at: 2026-11-16T07:53:14.739Z
locale: zh-cn
---

# Unity Web 请求 API 简介

> 了解 Unity Web 请求 API 的主要用途和架构。

`UnityWebRequest` 是 Unity 的 HTTP/HTTPS 网络 API，用于在运行时与 Web Services 通信、传输文件和串流数据。

Unity Web 请求System的常见用途包括：

* 在运行时下载内容，例如：

  * 使用常规 [AssetBundle](/engine/6000.0/manual/assets-and-media/assets-managing-runtime/assetbundles-section.md) 或 [Addressables](https://docs.unity3d.com/Packages/com.unity.addressables@latest) 系统时，来自远程服务器的 AssetBundles。
  * 用于配置、本Localization和实时调整的文本/json。
  * 动态内容的图像（作为[Textures](/engine/6000.0/manual/materials-and-shaders/textures/textures-getting-started/textures.md)）和音频（作为[AudioClips](/engine/6000.0/manual/audio/reference/class-audio-clip.md)）。
  * 通过远程清单进行生成时间或运行时时修补。

* 将数据上传到服务器，例如：

  * Player Metrics。
  * 保存的游戏状态。
  * 错误/异常日志和崩溃 Reports。
  * 自定义定义遥测和Analytics。

* 与内容交付网络、Authentication and SECURITY、支付平台、Multiplayer 服务、诊断和远程版本管线集成。

* 实现低流量、联网的 Multiplayer 和回合制游戏，例如国际象棋。

## 架构##architecture

Unity Web 请求System包含两图层：

* [高级关卡 API](/engine/6000.0/manual/scripting/object-oriented-development/web-request/hlapi.md) (HLAPI) 包裹了低级 API 并为常见操作提供了方便的接口。
* [低级 API](/engine/6000.0/manual/scripting/object-oriented-development/web-request/llapi.md) (LLAPI) 为更高级的操作提供了最大的灵活性。

System 将 HTTP transaction 分解为以下操作：

* 将数据发送到服务Server。
* 从Server接收数据。
* HTTP 流Control（例如，重定向和报错处理）。

每个操作都由指定的类型的Object进行Managed，您可以使用这些对象自定义和Controltransaction的各个方面：

* [`UploadHandler`](/engine/6000.0/script-reference/unityengine/networking/uploadhandler.md) Object 处理向 Server 的数据传输。
* [`DownloadHandler`](/engine/6000.0/script-reference/unityengine/networking/downloadhandler.md) Object 处理从 Server 接收的数据的 receipt、缓冲和后期处理。
* [`UnityWebRequest`](/engine/6000.0/script-reference/unityengine/networking/unitywebrequest.md) Object 管理其他两个对象，还处理 HTTP 流程 Control。此 Object 是定义自定义标头和 URL 以及存储报错和重定向信息的位置。


**Data sent from user code passes through an UploadHandler and then a UnityWebRequest before reaching the HTTP web server. Data received from the server passes through a UnityWebRequest and then a DownloadHandler before reaching user code.:**
![](/api/media?file=/engine/6000.0/media/images/UnityWebRequestArchitecture.png)

以下是 HTTP transaction 的高级概述：

* 创建 [](/engine/6000.0/script-reference/unityengine/networking/unitywebrequest.md) 对象。

* 配置 `UnityWebRequest` Object。

  * 设置自自定义标头。
  * 设置 HTTP 动词（例如 `GET`、`POST`、`HEAD` - All 平台都允许自定义动词）。
  * 设置网址。

* （可选）创建一个上传处理程序理程序并将其附加到 Web 请求。

  * 提供要上传的数据。
  * 提供要上传的 HTTP 表单。

* （可选）创建下载处理程序并将其附加到 Web 请求。

* 发送 Web 请求。
  * 通过[协程](/engine/6000.0/manual/scripting/object-oriented-development/coroutines-section.md)，您可以`yield`[`UnityWebRequest.SendRequest`](ScriptRef:Networking.UnityWebRequest.SendRequest)调用的结果以等待请求完成。

* （可选）从下载处理程序读取收到的数据。

* （可选）从 `UnityWebRequest` Object 读取报错信息、HTTP 状态代码和响应标头。

有关说明这些步骤的详细代码示例，请参阅 API 文档以[了解`UploadHandlerRaw`](/engine/6000.0/script-reference/unityengine/networking/uploadhandlerraw.md)。

## 其他资源##additional-resources

* [Web 请求高级关卡 API 参考](/engine/6000.0/manual/scripting/object-oriented-development/web-request/hlapi.md)
* [Web 请求低级 API 参考](/engine/6000.0/manual/scripting/object-oriented-development/web-request/llapi.md)
