SetRequestHeader(string, string)
Sets an HTTP request header to a custom value.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Networking
- Assembly: UnityEngine.UnityWebRequestModule
public void SetRequestHeader(string name, string value)
Parameters
Remarks
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 must contain at least one character. An empty is valid for headers that allow one, such as . For more information, refer to HTTP specifications.
namevalueAccept-EncodingThis method can't be called after UnityWebRequest.SendWebRequest is called.
It is not recommended to set these headers to these custom values: , , , , , , , , , , , , , , , , . 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.
Accept-CharsetAccept-EncodingAccess-Control-Request-HeadersAccess-Control-Request-MethodConnectionDateDntExpectHostKeep-AliveOriginRefererTeTrailerTransfer-EncodingUpgradeViaThe 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.
Accept-EncodingThe header is automatically populated based on the contents of the attached UploadHandler if any, and can't be set to a custom value.
Content-LengthThe header is automatically set by Unity and might not be set to a custom value.
X-Unity-VersionThe header is automatically set by Unity and it's not recommended to set it to a custom value.
User-AgentThe underlying cookie engine manages the and headers. The exact behavior depends on the platform, but setting cookies through these headers typically appends them to the ones the engine sets.
CookieCookie2In addition, the following headers are filled by the Web browser on the Web platform, and therefore might not have any custom values set: , , .
CookieCookie2User-AgentAdditional Resources: UnityWebRequest.ClearCookieCache