SetRequestHeader(string, string)
Set a HTTP request header to a custom value.
Read time 2 minutesLast updated 7 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 contain a minimum of 1 character. For more information, see 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: , , , , , , , , , , , , , , , , . 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 Mozilla docs on Accept-Encoding.
Accept-EncodingThe header is automatically populated based on the contents of the attached DownloadHandler 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 and headers are automatically managed by the underlying cookie engine. While the exact behavior is dependant on the platform used, typically, setting cookies via this header appends them to those set by engine. Additional Resources: UnityWebRequest.ClearCookieCache.
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-Agent