name | 要设置的标头的键。区分大小写。 |
value | 标头的预期值。 |
将 HTTP 请求标头设置为自定义值。
根据 RFC 2616,标头的键和值必须有效。字符串都不能包含某些非法字符,如控制字符。字符串都必须为非 null 且至少包含一个字符。有关更多信息,请参阅 RFC 2616,第 4.2 节。
调用 Send 后将无法调用此方法。
不能使用任何平台上的自定义值设置以下标头:accept-charset
、access-control-request-headers
、access-control-request-method
、connection
、date
、dnt
、expect
、host
、keep-alive
、origin
、referer
、te
、trailer
、transfer-encoding
、upgrade
、via
。
可以为 accept-encoding
标头设置自定义值,但生成的行为并不可靠,强烈建议将其自动处理,除非您可以接受出现异常结果带来的风险。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.