tags:

views:

197

answers:

2

Hello,

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 on 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.

+1  A: 

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;
Gonzalo
Is it possible to do this with a WebBrowser object? I'm trying to pull the HTML source off the site and need to use a WB to access this. Thanks for the answer, btw.
Sam Youtsey
+1  A: 

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.

GrayWizardx