2010-12-16 108 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);