Platform: Windows
Unity version: latest
We’re trying to use a www object with cookie headers for persistent session data when connecting to our server but to no avail. Currently, we are doing something like this:
- Make the first web request with a WWW object, using a WWWForms object to set the POST variables (username and password). Once complete, we retrieve the cookie from the www object’s response headers with the key “SET-COOKIE” and add it to our (empty) <string, string> dictionary. This works fine, the cookie is valid (as tested against logging in using a browser, checking things server side and client side in Chrome).
WWWForm form = new WWWForm();
form.AddField("username", username);
form.AddField("password", password);
WWW w = new WWW(urlLogin, form);
yield return w;
if (!string.IsNullOrEmpty(w.error))
{
// error handling
}
else
{
// cookieHeader is a Dictionary<string, string>
cookieHeader.Add("Cookie", w.responseHeaders["SET-COOKIE"]);
// stuff happens...
}
- We make another request to retrieve data, using a www object with no POST variables but using a cookie header. What should happen is that the server should read the cookie data from the header, pull the appropriate session information and handle our request as usual. When testing using in the browser, this works fine, but when making the request using the WWW object in Unity, the server doesn’t receive the cookie header:
WWW w = new WWW(urlSomeService, new byte[] { 0 }, cookieHeader);
yield return w;
if (!string.IsNullOrEmpty(w.error))
{
// error handling
}
else
{
// response received from server but no data in cookie header to complete request
}
Any suggestions as to what we’re doing wrong?