1,979
社区成员
发帖
与我相关
我的任务
分享 CookieContainer cc = new CookieContainer();
string postData = "tpl_ok=&next_t";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri("https://passport.baidu.com/?login"));
webRequest2.CookieContainer = cc;
webRequest2.Method = "POST";
webRequest2.Accept="image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
webRequest2.ContentLength=byteArray.Length;
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.Referer="https://passport.baidu.com/?login&tpl=mn";
webRequest2.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)";
Stream newStream = webRequest2.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();
//HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
//StreamReader sr2=new StreamReader(response2.GetResponseStream(), Encoding.Default);
//string text2 = sr2.ReadToEnd();
webBrowser1.Navigate("https://www.baidu.com/");//这里不知道是不是对的,是想查看下登录成功了没有。每次都登录不上去了。。。是我那里写错了么?谢谢大家的帮忙了。