Question by
dyhmichail · Sep 27, 2018 at 04:15 AM ·
webrequestcookies
UnityWebRequest.SendWebRequest() doesn't function properly with cookies
Hello I try to connect to url with UnityWebRequest.SendWebRequest() but there are some errors. Here is the code and my comments to it.
UnityWebRequest login_request = UnityWebRequest.Get(serverName + "/api/integration/v1/connect?login=" + login + "&password=" + password + "⟨=en-us&timezone=%2B5"); yield return login_request.SendWebRequest(); Dictionary current_cookie = login_request.GetResponseHeaders();
foreach (var s in current_cookie)
Debug.Log(s.Key + " " + s.Value);
//Cache-Control no-cache
//Pragma no-cache
//Content-Type application/json; charset=utf-8
//Expires -1
//Server Microsoft-IIS/7.5
//Set-Cookie .ASPXAUTH=; expires=Mon, 11-Oct-1999 18:00:00 GMT; path=/; HttpOnly,SGUID=session_id=8be8af5f&Culture=en-us&langfile=ext-lang-en.js&msgfile=msg-lang-en.js&login=; path=/
//X-AspNet-Version 4.0.30319
//X-Powered-By ASP.NET
//Date Wed, 26 Sep 2018 03:45:05 GMT
//Content-Length 4
UnityWebRequest real_id_request = new UnityWebRequest();
real_id_request.url = serverName + "/api/integration/v1/gettree?all=true";
real_id_request.SetRequestHeader("Set-Cookie", current_cookie["Set-Cookie"]);
yield return real_id_request.SendWebRequest();
Debug.Log(real_id_request.downloadHandler.text);
//Here i have got error NullReferenceException, but I checked url is correct
//Or if
UnityWebRequest real_id_request_2 = UnityWebRequest.Get(serverName + "/api/integration/v1/gettree?all=true");
yield return real_id_request_2.SendWebRequest();
Debug.Log(real_id_request_2.downloadHandler.text);
//{"children":null,"result":"NoAuth"}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612175335im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UnityWebRequest Responds with 405 1 Answer
HttpClient with Proxy 0 Answers
send data from a PHP (service) page to unity webgl 1 Answer