HTTP Web 请求不维护会话 [英] HTTP web request doesn't maintain session

查看:41
本文介绍了HTTP Web 请求不维护会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我想在其中废弃一些有用的学习材料以供个人使用.该站点还维护一个会话密钥和其他一些密钥.如果我尝试转到嵌套页面,它将结束会话.

I have a program where I want to scrap some useful study material for personal use. This site maintain a session key and some other key also. If I tried to go to a nested page then it will end the session.

我无法使用网络请求类维护会话密钥.

I'm unable to maintain session key using a web request class.

如何使用 Web 请求类维护会话?

How can I maintain a session using a web request class?

请帮忙.

推荐答案

您需要在您的请求中维护 CookiesCollection.

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;

当您收到响应时,您的容器将自动包含与之关联的一组 cookie.然后,您可以在后续请求中重复使用该容器.

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.

这篇关于HTTP Web 请求不维护会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆