C#.NET Cookie处理有关登录后 [英] C# .NET Cookie Handling For After Login

查看:157
本文介绍了C#.NET Cookie处理有关登录后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间研究这个,但还是无法弄明白。它显得如此简单,所以我觉得自己像个白痴询问,但过了一段时间寻找到它,我似乎无法得到它的窍门。

I've spent some time researching this and still can't figure it out. It seem so simple so I feel like an idiot asking about it but after a while looking into it I just can't seem to get the hang of it.

我需要以编程方式登录到这个网站: https://wholesale.frontiercoop.com/ ,商店从登录该cookie,并重新提交它在下一次登录。它看起来就像是一个POST提交(这是我从使用萤火虫的Firefox的聚集),所以我想通了,如何保存,我认为该cookie。我只是无法弄清楚如何将其提交到网站的下一次调用,因此它不会自动重定向我到登录页面。这是简单的一个参数WebBrowser对象通话?

I need to programmatically log into this site: https://wholesale.frontiercoop.com/, store the cookie from the login, and resubmit it on the next login. It looks like it's a POST submit (which I gathered from using Firebug on Firefox) so I figured out how to store the cookie I think. I just can't figure out how to submit it on the next call to the website so it doesn't automatically redirect me to the login page. Is this simply an argument to a call on the Webbrowser object?

感谢您的帮助。

推荐答案

通过.NET,你必须使用的CookieContainer,如:

With .NET you have to use a CookieContainer, like:

HttpWebRequest req = (HttpWebRequest) WebRequest.Create ("https://wholesale.frontiercoop.com/");
req.Method = "POST";
CookieContainer container = new CookieContainer ();
req.CookieContainer = container;
// Write the POST data and get the request...
...
// ...and once the request is done, the cookie is in 'container'.
// Then, for subsequent requests you set the CookieContainer of the request to the one above
otherRequest.CookieContainer = container;

这篇关于C#.NET Cookie处理有关登录后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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