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 自动设置,不建议将其设置为自定义值。cookie
和 cookie2
标头由底层 Cookie 引擎自动管理。虽然确切的行为取决于平台,但如果通过此标头设置 Cookie,则通常会将 Cookie 附加到引擎设置的 Cookie。另请参阅:ClearCookieCache。
除上述情况外,在 **WebGL** 平台上以下标头由 Web 浏览器填充,因此可能没有自定义值:cookie
、cookie2
、user-agent
。
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.