HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri("http://www.163.com"));
CookieContainer cc = new CookieContainer();
Cookie c = new Cookie();
c.Name = "aa";
c.Value = "aa";
c.Path = "/";
c.Domain = "www.163.com";
req.CookieContainer = cc;
HttpWebResponse res = (HttpWebResponse)req.GetResponse();执行上面的代码后,cookie aa=aa 并没有被发送,为什么?

解决方案 »

  1.   

    CookieContainer myCookieContainer = new CookieContainer();  
    string cookieStr = webBrowser1.Document.Cookie;  
    string[] cookstr = cookieStr.Split( '; ');  
    foreach (string str in cookstr)  
    {  }  
    HttpWebRequest hreq=(HttpWebRequest)HttpWebRequest.Create("");  
    hreq.Method= "POST ";  
    hreq.ContentType= "application/x-www-form-urlencoded ";  
    hreq.CookieContainer= myCookieContainer;  
    http://topic.csdn.net/u/20080608/10/63a38600-ff8c-4f6b-b87d-590442a90c07.html
      

  2.   

    用Add(Cookie)方式,Cookie的Domain好DomainKey是一样的,这样不行.需要用Add(Uri,Cookie)这种方式.