tags:

views:

169

answers:

1

I know how to get the source code but the website that I have been working on uses PHP session, this mean that you will need to login(which I have) and use the session ID that the server send back. How do I do this?

+2  A: 

Assuming you meant Session, you'll need CookieContainer:

CookieContainer cookies = new CookieContainer();
HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(someSite);
getRequest.CookieContainer = cookies;
getRequest.Method = "GET";
HttpWebResponse form = (HttpWebResponse)getRequest.GetResponse();
using (StreamReader response = 
   new StreamReader(form.GetResponseStream(), Encoding.UTF8))
{
    formPage = response.ReadToEnd();
}

You first make a GET request to server and it'll return your SessionID in a cookie. If you need to make new requests to same server, you must pass it through and server will identify you as a returning user.

Rubens Farias
Thanks, I spelled it wrong sorry.
Jonathan Shepherd
And how do I pass it to the next request? Sorry I'm a bit confuse here.
Jonathan Shepherd
`newRequest.CookieContainer = cookies;` will do the trick
Rubens Farias
Got it working thanks.
Jonathan Shepherd