怎么获得用WebBrowser打开网址的cookie????

hhlhhlshadow 2009-03-22 12:32:26
在网上找了半天也没有一个明确的答案,我想用WebBrowser这个打开一个网址,然后读取这个地址的cookie,用vb很好读出来document.cookie 就可以了.但是在c#里面document就没有这个cookie属性,这个问题怎么解决呢???
...全文
330 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq9717790 2009-08-10
  • 打赏
  • 举报
回复
WebBrowser.Document.Cookie
hhlhhlshadow 2009-03-22
  • 打赏
  • 举报
回复
好了,谢谢各位了!
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.xxx.com");
request.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
foreach (Cookie cook in response.Cookies)
{
Console.WriteLine("{0} = {1}", cook.Name, cook.Value);
}
hhlhhlshadow 2009-03-22
  • 打赏
  • 举报
回复
谢谢几位的回答,我试试看~~~
liqngjun123 2009-03-22
  • 打赏
  • 举报
回复
string strUri = obj as string;

HttpWebRequest wr = WebRequest.Create(strUri) as HttpWebRequest;
if (wr != null)
{
try
{
wr.CookieContainer = new CookieContainer();
wr.KeepAlive = true;
wr.AllowAutoRedirect = true;

using(HttpWebResponse wp = wr.GetResponse() as HttpWebResponse)
{

wp.Cookies = wr.CookieContainer.GetCookies(new Uri(strUri));

using (Stream cs = wp.GetResponseStream())
{
using(StreamReader sr = new StreamReader(cs))
{

do
{
string strALine = sr.ReadLine();

}}}}}
csShooter 2009-03-22
  • 打赏
  • 举报
回复
动机?
maddemon 2009-03-22
  • 打赏
  • 举报
回复
HttpWebRequest.CookieContainer 得到cookie集合

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧