string url=@"http://XXX.XXX.com/getdet.asp?ft=203";
string lur=@"http://XXX.XXX.com/Login.asp";
HttpWebRequest re = (HttpWebRequest)WebRequest.Create(lur);
CredentialCache ccache = new CredentialCache();
re.KeepAlive = false;
ccache.Add(new Uri(lur), "Basic", new NetworkCredential("yxkf", "99999"));
re.Credentials = ccache;
CookieContainer cookieCon=new CookieContainer();
re.CookieContainer = cookieCon;
HttpWebResponse loWebResponse = (HttpWebResponse) re.GetResponse();
string cookiehead = re.CookieContainer.GetCookieHeader(new Uri(lur));

//Datapage
//这样传递COOKI是否正确
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.CookieContainer = cookieCon;
req.CookieContainer.SetCookies(new Uri(url),cookiehead);
req.GetResponse();//这里还是出错,为什么
为什么还是不行,COOKIE是这样传递吗,

解决方案 »

  1.   

    http://www.cnblogs.com/lovecherry/archive/2005/04/22/143341.html
      

  2.   

    to lovecherry
    myHttpWebRequest=(HttpWebRequest)WebRequest.Create(url); 
                myHttpWebRequest.CookieContainer=myCookieContainer;//* 
                //刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证 
                myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse(); 
    我运行在这里取出cookie后,再去取数据页面在getresponse就会出错,