The following code used to work great in 5.5 and 5.6 but is now throwing an exception in 2017.1. I’m trying to figure out if I’m just fundamentally doing something wrong that happened to work in 5.6 but now fails in 2017.1 or if this is a Unity bug.
private static readonly string contentType = “Content-Type”;
private static readonly string contentLength = “Content-Length”;
internal static WWW PostJsonToURL(string uploadText, string postURL)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Dictionary<string, string> postHeader = new Dictionary<string, string>();
postHeader.Add(contentType, “text/json”);
postHeader.Add(contentLength, uploadText.Length.ToString());
WWW request = new WWW(postURL, encoding.GetBytes(uploadText), postHeader);
return request;
}
when I run this in 2017.1 I get this exception in the WWW constructor:
InvalidOperationException: Cannot override system-specified headers
UnityEngine.Networking.UnityWebRequest.SetRequestHeader (System.String name, System.String value) (at C:/buildslave/unity/build/artifacts/generated/common/modules/UnityWebRequest/WebRequestBindings.gen.cs:471)
UnityEngine.WWW…ctor (System.String url, System.Byte[ ] postData, System.Collections.Generic.Dictionary`2 headers) (at C:/buildslave/unity/build/Runtime/WebRequestWWW/UWRWWW.cs:62)
Any advice?