Http web request doesn't maintaining session

泄露秘密 提交于 2019-12-22 10:46:40

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/2457771/http-web-request-doesnt-maintaining-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!