| Parameter | Description |
|---|---|
| name | The key of the header to be set. Case-sensitive. |
| value | The header's intended value. |
Sets an HTTP request header to a custom value.
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 name must contain at least one character. An empty value is valid for headers that allow one, such as Accept-Encoding. For more information, refer to HTTP specifications.
This method can't be called after UnityWebRequest.SendWebRequest is called.
It is not recommended to set these headers to these 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, therefore the resulting behavior is unreliable.
It is strongly recommended to leave these headers for automatic handling unless you want to risk viewing any unexpected results.
The Accept-Encoding header is automatically set to supported encodings. Use of a different value is ignored or might cause request to fail. For more information, refer to the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding">Mozilla docs</a> on Accept-Encoding.
The Content-Length header is automatically populated based on the contents of the attached UploadHandler if any, and can't be set to a custom value.
The X-Unity-Version header is automatically set by Unity and might not be set to a custom value.
The User-Agent header is automatically set by Unity and it's not recommended to set it to a custom value.
The underlying cookie engine manages the Cookie and Cookie2 headers. The exact behavior depends on the platform, but setting cookies through these headers typically appends them to the ones the engine sets.
In addition, the following headers are filled by the Web browser on the Web platform, and therefore might not have any custom values set: Cookie, Cookie2, User-Agent.
Additional resources: UnityWebRequest.ClearCookieCache