2010-12-16 109 views
-1

我有以下代码登录到POST http://www.160by2.com/logincheck.aspx?iamindian=此网址,我的问题是米无法登录,当我调试它使用提琴手,我看不到ne cookie认为我是使用CookieContainer类,这里使用中号Windows应用程序在C#无法设置Cookie使用HttpWebRequest在c#

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.160by2.com/logincheck.aspx?iamindian="); 
     string PostData = string.Format("htxt_UserName={0}&txt_Passwd={1}&txt_pop=&s=&d=&cmdSubmit=&namenumber={2}&strclf=&strshareuser=&ucountry=&ucode=&ucity=&uregion=", txtMobile.Text, txtPassword.Text, "1"); 
     CookieContainer cookie = new CookieContainer(); 
     request.Method = "POST"; 
     request.ContentType = "application/x-www-form-urlencoded"; 
     request.Referer = "http://www.160by2.com"; 
     request.CookieContainer = cookie; 
     StreamWriter sWriter = new StreamWriter(request.GetRequestStream()); 
     sWriter.Write(PostData); 
     sWriter.Close(); 

     request.GetResponse().Close(); 
     //some more code is here for further posting but above code can't login so below code is also not working 

我也跟着This,职位,但它并没有help'd我.. 请帮我在这里,其中M布莱恩错误..

回答

5

这是真的,因为

CookieContainer cookie = new CookieContainer(); 

您已将任何东西放到您的cookie容器中。

使用添加方法,把实际值,以使用网站

container.Add(new Uri("http://yoursite"), new Cookie("name", "value")); 

,并做再次发布。

+0

我很是m阿斯金这个愚蠢的问题SRY,我是歌厅的cookie值'饼干:在提琴手名= value',什么SHLD我通过了在'新的Cookie(“名称”,“价值”)''名称和价值''' – FosterZ 2010-12-16 12:32:06

+0

,我没有得到你,你是什么意思'使用添加方法,把实际值cookie“因为,我dn不知道要在cookie中设置什么,在这里我发布登录凭据到该URI作为回报,它发送的cookie将被设置。 – FosterZ 2010-12-16 12:36:24

+0

我正在关注本教程http://odetocode.com/Articles/162。 aspx 按照这个,那家伙也没有设置任何cookie容器,m完全混淆了.. – FosterZ 2010-12-16 12:59:26

-2

,这是正常工作尝试

Cookie objCookie = new Cookie("data", "Scott"); 
    cookieContainer.Add(new Uri(txtURL.Text), objCookie);