请不要使用webbrowser来获取....
地址:http://www.sina.com.cn/这个cookie怎么来的?用c#如何抓取呢?
最好给出代码,谢谢大家了
抓包结果GET / HTTP/1.1
Accept: */*
Referer: http://www.hao123.com/
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 2.0.50727)
Host: www.sina.com.cn
Connection: Keep-Alive
Cookie: SINA_NEWS_CUSTOMIZE_city=%u6CF0%u5B89; vjuids=569cc958a.1174a3ebfa3.0.8e0822d66ee748; vjlast=1207548127; userId=C64LD4wWE6syoVtX6_tko_tLeWsjbYs4bXrKH4-XE4tKoa; SINAGLOBAL=222.132.163.16.45391207162205895; sinaRotator/=25; Iask2_visitID=124.130.178.9.227101207386214407; sinaRotator/=26; rpb_1_0=1207548623781; icast_46139_1034_unique=1; icast_46023_1018_unique=1

解决方案 »

  1.   

    用HttpWebRequest不行吗?要自己解析?
      

  2.   

    HttpRequest类和HttpResponse类提供了Cookie属性,可以获取你要的信息
      

  3.   

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(yourUrl);
    req.Method = "GET";
    CookieContainer cc = new CookieContainer();
    req.CookieContainer = cc;
    HttpWebResponse res = (HttpWebResponse)req.GetResponse();
    string strR = req.Headers["Cookie"];
      

  4.   


    using   System;   
      using   System.Collections.Generic;   
      using   System.Text;   
      using   System.Collections;   
      using   System.Data;   
      using   System.Data.SqlClient;   
      using   System.Text.RegularExpressions;   
      using   System.Net;   
        
        
      namespace   ConsoleApplication1   
      {   
              class   Program   
              {   
                      static   void   Main(string[]   args)   
                      {   
                              HttpWebRequest   request   =   (HttpWebRequest)WebRequest.Create("http://www.sina.com.cn/");   
                              request.CookieContainer   =   new   CookieContainer();   
        
                              HttpWebResponse   response   =   (HttpWebResponse)request.GetResponse();   
        
                              Console.WriteLine("reading...");   
        
                              //   Print   the   properties   of   each   cookie.   
                              foreach   (Cookie   cook   in   response.Cookies)   
                              {   
                                      Console.WriteLine("Cookie:");   
                                      Console.WriteLine("{0}   =   {1}",   cook.Name,   cook.Value);   
                                      Console.WriteLine("Domain:   {0}",   cook.Domain);   
                                      Console.WriteLine("Path:   {0}",   cook.Path);   
                                      Console.WriteLine("Port:   {0}",   cook.Port);   
                                      Console.WriteLine("Secure:   {0}",   cook.Secure);   
        
                                      Console.WriteLine("When   issued:   {0}",   cook.TimeStamp);   
                                      Console.WriteLine("Expires:   {0}   (expired?   {1})",   
                                              cook.Expires,   cook.Expired);   
                                      Console.WriteLine("Don't   save:   {0}",   cook.Discard);   
                                      Console.WriteLine("Comment:   {0}",   cook.Comment);   
                                      Console.WriteLine("Uri   for   comments:   {0}",   cook.CommentUri);   
                                      Console.WriteLine("Version:   RFC   {0}",   cook.Version   ==   1   ?   "2109"   :   "2965");   
        
                                      //   Show   the   string   representation   of   the   cookie.   
                                      Console.WriteLine("String:   {0}",   cook.ToString());   
                              }   
                              Console.WriteLine("end.");   
                              Console.Read();   
                      }   
                        
              }   
      }   
      

  5.   

    楼上的老大,别玩我了,运行结果为
    reading...
    end.
      

  6.   

    首先要搞清你的代码运行在服务器端还是客户端啊。楼上的写了那么多代码是在解析Client向Server提交的Cookie,当然拿不到。
      

  7.   

    当然是客户端...否则哪里来的cookie?
      

  8.   


    using System;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Runtime.InteropServices;
    using Microsoft.Win32;public class CookieReaderDemo
    {
        static void Main(string[] args)
        {
            //使用自定义读取方式
            Console.WriteLine(GetCookiesFromFiles("csdn"));
            //使用Windows API方式
            Console.WriteLine(GetCookie("http://www.csdn.net"));
        }    [DllImport("WinINet.dll", CharSet=CharSet.Auto, SetLastError=true)]
        public static extern bool InternetGetCookie(string urlName, string cookieName, StringBuilder cookieData, ref int size);    [DllImport("Kernel32.dll")]
        internal static extern Int32 GetLastError();    public static string GetCookie(string url) //Win32 API
        {
            int size = 1000;
            StringBuilder sb = new StringBuilder(size);        if (!InternetGetCookie(url, null, sb, ref size))
            {
                Console.WriteLine("Error code:{0}", GetLastError());
            }
            return sb.ToString();
        }    public static string GetCookiesFromFiles(string masterDomain) //Cookies File
        {
            string result = string.Empty;
            RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", false);
            if (key != null)
            {
                string val = (string)key.GetValue("Cookies");
                if (val != null)
                {
                    string[] files = Directory.GetFiles(val);
                    string s = null;
                    int i;
                    Regex r = new Regex(@".*@" + masterDomain + @"*\[\d+\].txt");
                    for (i = 0; i < files.Length; i++)
                    {
                        if (r.IsMatch(files[i]))
                        {
                            s = files[i];
                        }
                    }
                    if (s != null) //s 就是最新文件
                    {
                        StreamReader sr = new StreamReader(s);
                        s = null;
                        i = 1;
                        while ((s = sr.ReadLine()) != null)
                        {
                            if (s == "*" || s == "\n")
                            {
                                i = 0;
                            }
                            //每节只读两行
                            if (i == 1)
                            {
                                result += s;
                            }
                            else if (i == 2)
                            {
                                result += "=" + s + "; ";
                            }
                            i++;
                        }
                    }
                }
            }
            return result;
        }
    }
      

  9.   

    呵呵,还不行吗?试一下用javascript来。
    在网页的地址输入栏里输入以下代码:
    javascript:alert(document.cookie);
    肯定能看到
      

  10.   


    这段还不行吗?你是在本地客户端读取本地的Cookie吗?