I've spend several months working with HttpWebRequest & CookieContainer, and simply had a miserable time making it work.
My question is whether there's a better approach/workaround to it, and if not hopefully these bugs will be fixed by next 'patch'.
Issue #1.ÃÂ HttpWebRequest does not setCookies for redirects until the end of redirect.
Suppose you have a scenario where you log in, gets a 302 redirect with a SetCookie header.ÃÂ Now, the new redirected page verifies that the cookie is set before sending the correct response.ÃÂ Using HttpWebRequest & CookieContainer, the second redirect request does not have the cookie that response #1 specified, and thus you can never log in using these APIs.ÃÂ
The only workaround I found so far is to manually do the redirects myself.ÃÂ This is simply inefficient and no reason why HttpWebRequest should not do this set cookie automatically between redirects.
This kind of redirect scenario happens quite often.ÃÂ I bet even some of Microsoft's own webpage does this.
Issue #2.ÃÂ Cannot remove cookies from cookie container.
This doesn't really need explanation.ÃÂ Why would it not let me remove a cookie?ÃÂ The only silly approach is to make a new one and copy/add all the cookies except the one you want to remove.ÃÂ Setting a null value does not remove it either.
View Complete Post