开发者

Unable to set the cookie using HttpWebRequest in c#

开发者 https://www.devze.com 2023-01-31 10:12 出处:网络
i have following code for login to POST http://www.160by2.com/logincheck.aspx?iamindian= this url, my problem is m not able to login and when i debug it using Fiddler, i can\'t see ne cookie thought i

i have following code for login to POST http://www.160by2.com/logincheck.aspx?iamindian= this url, my problem is m not able to login and when i debug it using Fiddler, i can't see ne cookie thought i'm using CookieContainer class, here m using windows app in 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

i followed This, post but it didn't help'd me.. Please, Help me out here where m goin' wrong..


Thats really true, because

CookieContainer cookie = new CookieContainer();

you have put nothing to your cookie container.

Use Add method, to put actual values to cookie

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

and do post again.


this is working properly try it

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

精彩评论

暂无评论...
验证码 换一张
取 消