- Home /
Access browser cookies from Web Player
Assume that the web player is embedded in a web page containing a flash application used to authenticate a user. Once the user is authenticated on the server, this one put a cookie in the user web browser to recognize subsequent http requests from this user. As the web player is part of the application, all the http requests from web player to the server need this cookie to allow the player to acces user data.
So I was wondering if Unity provides something to access browser cookies and get the one corresponding to the server domain? Do I have to do it manually through javascript?
Answer by Bunny83 · Mar 18, 2011 at 11:39 AM
Unfortunately Unity don't have such a function. If you're logged in via your website you would have to use Application.ExternalEval. Even if you use WWW to log in from your Unity app you have to parse the response header for the SetCookie header field.
Also watch out: The Unity WWW.responseHeaders (which are not documented yet) is a Hashtable! If your webserver returns multiple SetCookie header fields (which is legit by rfc2616 ) you will loose them except one due to the Hashtable. Hopefully it will be fixed soon ;)
Thank you Bunny83 for this quick and clear answer! :) I managed to make it work through web browser javascript and ExternalCall like you suggested.
Answer by GuyTidhar · Jun 19, 2011 at 07:34 AM
Can I set this cookie from the client?
Also since I have the pro version, could I use .NET http classes in a dll to perform all my http connection functionality for the webplayer build?