[英]Unable to set the cookie using HttpWebRequest in c#
我有以下代码用于登录POST http://www.160by2.com/logincheck.aspx?iamindian=
此网址,我的问题是无法登录,当我使用Fiddler调试时,看不到ne cookie以为我正在使用CookieContainer
类,这里我在c#中使用Windows应用程序
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
我关注了此帖子,但没有帮助我..请,在这里帮我解决问题。
那是真的,因为
CookieContainer cookie = new CookieContainer();
您没有向Cookie容器中放任何东西。
使用Add方法将实际值放入Cookie
container.Add(new Uri("http://yoursite"), new Cookie("name", "value"));
然后再次发布。
这工作正常尝试
Cookie objCookie = new Cookie("data", "Scott");
cookieContainer.Add(new Uri(txtURL.Text), objCookie);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.