Http web request doesn't maintaining session

2019-05-16 21:03发布

I have program where i want to scrap some Useful study material for me. This site maintaining session key and some other key also. If I trying to go nested page then it will throw me out and show session out message. I unable to maintain session key in web request class. so please give me some idea that how can i maintain session in web request class.

3条回答
聊天终结者
2楼-- · 2019-05-16 21:45

You need to maintain the CookiesCollection across your requests.

var request = (HttpWebRequest)HttpWebRequest.Create("http://www.mysite.com/");
var cookies = new CookieContainer();

//Pass the collection along with each request to maintain session
request.CookieContainer = cookies;

When you get the response back, your container will automatically contain the set of cookies associated with it. You can then reuse that container with subsequent requests.

查看更多
相关推荐>>
3楼-- · 2019-05-16 21:45

Essentially you will want to read the session cookie from the response header and pass it back in the header with every request you issue. There may be more to it depending on the application you are targeting.

查看更多
地球回转人心会变
4楼-- · 2019-05-16 21:49

Got a similar problem when embedding a Page in an iFrame. Solution is, for security purposes sessions get discarded by browsers (mainly IE8). Maybe this is a splution? Google for P3P to get more info.

-sa

查看更多
登录 后发表回答