Search code examples
c#session-variableswebrequest

Keeping session id when getting source code from web page


I'm making a C# windows form application that needs to parse data from an external site that requires me to log in.

First I send the POST data on the login page using a WebRequest. This works correctly as I can see the page source of a page that requires me to log in.

When I try to view the page source code of the data-page however, I'm logged out again as the session gets lost.

Is there any way of storing the PHPSESSID and re-using it in another request?

EDIT:

WebRequest _theRequest;
...
_theRequest = (HttpWebRequest)WebRequest.Create(url);
_theRequest.CookieContainer = new CookieContainer();

The property CookieContainer is not showing up in the intellisense list, anything I'm doing wrong here?


Solution

  • You could assign a CookieContainer and reuse the request object for subsequent requests.