UnityWebRequest 对象用于与 Web 服务器进行通信。
UnityWebRequest 处理 HTTP 与 Web 服务器进行通信的流程。其他对象 - 特别是 DownloadHandler 和 UploadHandler - 分别管理数据的下载和上传。
为方便起见,系统提供一组静态函数;这些函数可返回针对许多常见用例相应配置的 UnityWebRequest 对象。请参阅:Get、Post、Put、GetTexture。
注意:UnityWebRequest 通过调用 SendWebRequest 方法开始与远程服务器进行通信后,UnityWebRequest 对象的大部分属性将无法更改。
注意:代理设置应在操作系统级别上配置。UnityWebRequest 会采用这些设置。
kHttpVerbCREATE | 字符串“CREATE”,通常用作 HTTP CREATE 请求的动词。 |
kHttpVerbDELETE | 字符串“DELETE”,通常用作 HTTP DELETE 请求的动词。 |
kHttpVerbGET | 字符串“GET”,通常用作 HTTP GET 请求的动词。 |
kHttpVerbHEAD | 字符串“HEAD”,通常用作 HTTP HEAD 请求的动词。 |
kHttpVerbPOST | 字符串“POST”,通常用作 HTTP POST 请求的动词。 |
kHttpVerbPUT | 字符串“PUT”,通常用作 HTTP PUT 请求的动词。 |
certificateHandler | 拥有对 CertificateHandler 对象的引用,该对象可管理此 UnityWebRequest 的证书验证。 |
disposeCertificateHandlerOnDispose | 如果值为 true,则任何附加到此 UnityWebRequest 的 CertificateHandler 将在调用 UnityWebRequest.Dispose 时自动调用 CertificateHandler.Dispose。 |
disposeDownloadHandlerOnDispose | 如果值为 true,则任何附加到此 UnityWebRequest 的 DownloadHandler 将在调用 UnityWebRequest.Dispose 时自动调用 DownloadHandler.Dispose。 |
disposeUploadHandlerOnDispose | 如果值为 true,则任何附加到此 UnityWebRequest 的 UploadHandler 将在调用 UnityWebRequest.Dispose 时自动调用 UploadHandler.Dispose。 |
downloadedBytes | 返回系统从远程服务器下载的主体数据的字节数。(只读) |
downloadHandler | 拥有对 DownloadHandler 对象的引用,该对象可管理此 UnityWebRequest 从远程服务器接收的主体数据。 |
downloadProgress | 返回一个 0.0 和 1.0 之间的浮点值,用于表示从服务器下载主体数据的进度。(只读) |
error | 一个可读字符串,用于描述此 UnityWebRequest 对象在处理 HTTP 请求或响应时遇到的任何系统错误。(只读) |
isDone | 当 UnityWebRequest 结束与远程服务器的通信后,返回 true。(只读) |
isModifiable | 当 UnityWebRequest 的配置属性可更改时,返回 true。(只读) |
method | 定义此 UnityWebRequest 使用的 HTTP 动词,如 GET 或 POST。 |
redirectLimit | 表示在此 UnityWebRequest 将执行多少次重定向后,会发生“超出重定向限制”系统错误而停止。 |
responseCode | 服务器返回的数字 HTTP 响应代码,如 200、404 或 500。(只读) |
result | The result of this UnityWebRequest. |
timeout | 将 UnityWebRequest 设置为在经过 timeout 中的秒数后尝试中止。 |
uploadedBytes | 返回系统上传到远程服务器的主体数据的字节数。(只读) |
uploadHandler | 拥有对 UploadHandler 对象的引用,该对象可管理要上传到远程服务器的主体数据。 |
uploadProgress | 返回一个 0.0 和 1.0 之间的浮点值,用于表示将主体数据上传到服务器的进度。(只读) |
uri | 定义 UnityWebRequest 要通信的目标 URI。 |
url | 定义 UnityWebRequest 要通信的目标 URL。 |
useHttpContinue | 确定此 UnityWebRequest 是否将在其传出请求的标头中包含 Expect: 100-Continue。(默认值:true)。 |
UnityWebRequest | 使用默认选项创建 UnityWebRequest,且不附加 DownloadHandler 或 UploadHandler。默认方法为 GET。 |
Abort | 如果 UnityWebRequest 在进行中,请尽快停止。 |
Dispose | 表示不再使用此 UnityWebRequest,并且应清理它使用的所有资源。 |
GetRequestHeader | 检索自定义请求标头的值。 |
GetResponseHeader | 从收到的最新 HTTP 响应中检索响应标头的值。 |
GetResponseHeaders | 检索包含着此 UnityWebRequest 在最新 HTTP 响应中收到的所有响应标头的字典。 |
SendWebRequest | 开始与远程服务器通信。 |
SetRequestHeader | 将 HTTP 请求标头设置为自定义值。 |
ClearCookieCache | 清除缓存中存储的 Cookie。 |
Delete | 创建针对 HTTP DELETE 进行配置的 UnityWebRequest。 |
EscapeURL | 对字符串中的字符进行转义以确保其支持 URL。 |
GenerateBoundary | 生成一个随机的 40 字节数组来用作多部分表单边界。 |
Get | 为 HTTP GET 创建 UnityWebRequest。 |
Head | 创建一个经配置可发送 HTTP HEAD 请求的 UnityWebRequest。 |
Post | 创建一个经配置可通过 HTTP POST 向服务器发送表单数据的 UnityWebRequest。 |
Put | 创建一个经配置可通过 HTTP PUT 将原始数据上传到远程服务器的 UnityWebRequest。 |
SerializeFormSections | 将 IMultipartFormSection 对象列表转换为包含原始多部分表单数据的字节数组。 |
SerializeSimpleForm | 将字符串字典序列化为包含经过 URL 编码的 UTF8 字符的字节数组。 |
UnEscapeURL | 将支持 URL 的转义序列转换回正常文本。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.