I'm using Unity 5.3.1f1 and I'm having some issues setting cookies in UnityWebRequest. I'm getting the following error: ArgumentException: Cannot set Request Header Cookie - name contains illegal characters or is not user-overridable I'm trying to do this while targeting iOS in the editor (I've seen this on all other targets we use as well). Is there something I'm doing wrong? Here is sample code of what I'm doing: Code (CSharp): UnityWebRequest testrequest = new UnityWebRequest("http://test.mydomain.com"); testrequest.SetRequestHeader("Cookie", string.Format("session={0}", token)); The error occurs on line two of this sample. Thanks for the help!
I'm having the same problem, the header can't be set. Is this related to this other problem? http://forum.unity3d.com/threads/unitywebrequest-setrequestheader-cant-set-cookie-header.361818/ Even so, looks like none of us is targeting webgl. We could use a unity ninja around here.
The UnityWebRequest class is still pretty new and experimental as mentioned in some posts/changelogs.. so there still might be errors and not implemented features for now.. Maybe you can use the old WWW class for it, as long as WebRequest was not fixed/updated to work properly? Just found this link, maybe it helps at least to use the cookies for now: http://answers.unity3d.com/questions/255051/www-and-cookieslogin.html
Has anyone gotten this to work? I'd really like to start using UnityWebRequest, but this unfortunately is a blocker for us (Our security structure requires using cookies).
As mentioned in this post comment by Jordi: http://answers.unity3d.com/questions/1137108/how-to-set-a-cookie-with-unitywebrequest.html this issue will be fixed in 5.4 Regards Mario
Hey, this is very hacky, but the issue seems to be that the call to UnityWebRequest.SetRequestHeader incorrectly flags "Cookie" as an illegal header field name on some platforms. As such, since I really just need a fix that works in development only (not production) until 5.4 is released in non-beta form, I was able to do this, which seems to work OK: Code (CSharp): MethodInfo dynMethod = unityWebRequest.GetType().GetMethod("InternalSetRequestHeader", BindingFlags.NonPublic | BindingFlags.Instance); dynMethod.Invoke(unityWebRequest, new object[] { "Cookie", "blahblahblah" }); It requires using System.Reflection for the MethodInfo stuff. Perhaps this would work fine in production too, but haha - it seems a bit sketchy, and I don't know if it circumvents any under-the-hood stuff that could cause bugs or other problems. So, while I appreciate that it will be fixed in 5.4, it's been two months, aaaaand I need stuff to work now .
Version 5.4.0b1 throws same in WebGL Code (CSharp): SetRequestHeader("Cookie", "ClientVersion=1.0.0; Aspect=Aspect_16_x_9; Role=; Os=win");
I'm still having problems with this. In other platforms doing the "reflection thing" I have workaround it but it should just work without doing that. But in WebGL that reflection code crashes the application and I can't do anything. In WebGL setting Cookie header is forbidden also by @Justinas ... http://forum.unity3d.com/threads/un...r-cant-set-cookie-header.361818/#post-2379023 How can we "reach" a Unity staff member that is on the Networking team?
Can anyone confirm if this is fixed in non-WebGL platforms? WebGL isn't so much of a problem for us, as it uses the browser's session cookies that already exist. In other platforms though, I have to set the session, CSRF, etc cookies manually. We had to write a special security routine in our platform just for Unity so that we can work around this and WWW's faults. It would be great if we could just use a normal cookie way of doing it.