简体   繁体   中英

Cookie in GET REQUEST (REST) not in Cookies collection in response, but in header

Creating a rest request. I can retrieve the cookie returned via the Set-Cookie header. I am wondering why this would also not be included as part of the cookies collection in the response object. It's no problem, I can parse the set-cookie header and create a Cookie object to use from it, but I am wondering what the reason it would not be in the Cookies collection.

Thoughts?

.NET 4.0, C#, Console App

    HttpWebRequest request = WebRequest.Create( "http://fakeurl/authenticate") as HttpWebRequest;
    request.Headers.Add("Authorization", "Basic someoooooobase64value==");

    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
       string authCookieString = response.GetResponseHeader("Set-Cookie");
       //authCookieString.Split(
       Console.WriteLine(response.GetResponseHeader("Set-Cookie"));
    }

Response represent result coming from the server. Server may or may not re-set the same cookies.

As normal behavior for a server is actually not to set the same cookies again because it will simply consume bandwidth with no effect on browser's or consumer's behavior. The reason server will resend the same cookie if value need to change or expire.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM