Version: 2020.1

UnityWebRequest.SetRequestHeader

切换到手册
public void SetRequestHeader (string name, string value);

参数

name 要设置的标头的键。区分大小写。
value 标头的预期值。

描述

将 HTTP 请求标头设置为自定义值。

Header keys and values must be valid according to HTTP protocol specification. Neither string may contain certain illegal characters, such as control characters. Both strings must be non-null and contain a minimum of 1 character. For more information, see HTTP specifications.

调用 Send 后将无法调用此方法。

It is not recommended to set these headers to custom values: accept-charset, accept-encoding, access-control-request-headers, access-control-request-method, connection, date, dnt, expect, host, keep-alive, origin, referer, te, trailer, transfer-encoding, upgrade, via. Due to different limitations across platforms the custom value might be overridden, ignored or unsupported, so the resulting behavior is unreliable. It is strongly recommended to leave these headers for automatic handling unless you can accept the risk of unexpected results.

content-length 标头将根据附加的 DownloadHandler 的内容(如果有)自动填充,无法设置为自定义值。

x-unity-version 标头由 Unity 自动设置,可能无法设置为自定义值。

user-agent 标头由 Unity 自动设置,不建议将其设置为自定义值。

cookiecookie2 标头由底层 Cookie 引擎自动管理。虽然确切的行为取决于平台,但如果通过此标头设置 Cookie,则通常会将 Cookie 附加到引擎设置的 Cookie。另请参阅:ClearCookieCache

除上述情况外,在 WebGL 平台上以下标头由 Web 浏览器填充,因此可能没有自定义值:cookiecookie2user-agent