C# .NET Cookie Handling For After Login
I've spent some time researching this and still can't figure it out. It seem so simple so I feel like an idiot asking about it but after a while looking into it I just can't seem to get the hang of it.
I need to programmatically log into this site: https://wholesale.frontiercoop.com/, store the cookie from the login, and resubmit it on the next login. It looks like it's a POST submit (which I gathered from using Firebug on Firefox) so I figured out how to store the cookie I think. I just can't figure out how to submit it o开发者_如何学JAVAn the next call to the website so it doesn't automatically redirect me to the login page. Is this simply an argument to a call on the Webbrowser object?
Thanks for your help.
With .NET you have to use a CookieContainer, like:
HttpWebRequest req = (HttpWebRequest) WebRequest.Create ("https://wholesale.frontiercoop.com/");
req.Method = "POST";
CookieContainer container = new CookieContainer ();
req.CookieContainer = container;
// Write the POST data and get the request...
...
// ...and once the request is done, the cookie is in 'container'.
// Then, for subsequent requests you set the CookieContainer of the request to the one above
otherRequest.CookieContainer = container;
When you make the next request with the WebRequest object, you need to assign the CookieContainer that has your returned cookies in it.
This example shows how to do it with Hotmail, which should show you most of what you need.
精彩评论