开发者

Getting php session using c#

开发者 https://www.devze.com 2022-12-14 05:51 出处:网络
I k开发者_Go百科now 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

I k开发者_Go百科now 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消