Reading HttpOnly Cookies from Headers of HttpWebResponse in Windows Phone

妖精的绣舞 提交于 2019-12-12 15:46:33

问题


Is there any way to read HttpOnly Cookies from Headers of HttpWebResponse in Windows Phone?

In my code below "Set-Cookie" is not present in response.Cookies[]

My code

HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;

        // End the get response operation
        using (HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult))
        {
            Stream streamResponse = response.GetResponseStream();

            // But Set-Cookie is not present here as its HttpOnly
            var cookies = response.Cookies["Set-Cookie"];

            using (StreamReader streamReader = new StreamReader(streamResponse))
            {
                String Response = streamReader.ReadToEnd();
                streamResponse.Close();
                streamReader.Close();
                response.Close();

                // Call the response callback
                if (Callback != null)
                {
                    Callback(this, new EventArgs1() { Response = Response, Cookie = cookies });
                }
            }
        }

回答1:


Unfortunately you cannot access HttpOnly cookies directly. You can pass them to different requests using a CookieContainer, but you cannot read them.

CookieContainer container = new CookieContainer();

HttpWebRequest request = CreateRequest();

request.CookieContainer = container;

//do some requests


来源:https://stackoverflow.com/questions/8927755/reading-httponly-cookies-from-headers-of-httpwebresponse-in-windows-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!