从函数返回 CookieContainer
我正在创建一个应用程序来在网站的登录部分执行一些不同的操作。
为此,我必须为我发出的所有请求维护一个连续的 Cookie 会话。
到目前为止,我已经通过 HttpWebRequest 成功连接到网站,并且响应也证实了这一点,但是我无法重用 cookie。
我已经阅读了所有内容,并找到了指示如何在同一函数或类中使用 cookie 的主题,但我需要能够在多个不同的函数中使用 cookie。
我的第一个想法是尝试从初始登录函数返回 cookie 容器,然后将其作为参数传递给每个后续函数,但我就是无法让它继续下去。
有人能建议更好的方法或我可以实现这一目标的方法吗?
I'm creating an application to do a few different things on a website in the logged in section.
To do this, I must maintain a single continuous Cookie session for all requests I make.
So far I have successfully connected to the website via HttpWebRequest and the response has confirmed this, however I have been unable to reuse the cookie.
I have read all over SO and found topics that indicate how to use a cookie within the same function or class but I require the ability to use the cookie in multiple different functions.
My first thought was to try returning the cookie container from the initial login function and then pass it as a parameter to each subsequent function but I just couldn't get it going.
Is anyone able to suggest either a better method or a way I can accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过大量在线阅读后,我最终自己找到了解决方案。看来我第一次尝试时不起作用的原因是由于我配置了错误的其他设置。
因此,对于可能遇到同样问题的其他人,希望这会有所帮助:
I eventually came across the solution myself after much reading online. It appears the reason this didn't work the first time I tried it was due to other settings that I had configured wrong.
So for anyone else that may encounter the same issue, hope this helps: