本人在做模拟登陆,现在发现登陆的时候,老说我参数异常,我测试过后,发现我发送的数据包是2个的,别人发送的是一个人,格式都是一样的,不知道是不是这里的错误,代码如下,请大家帮忙解决下
本人在做网站模拟登陆,发现登陆的时候,发送变成了2个数据包,可能是这方面原因造成我无法登陆,登陆的时候,说参数异常,现代码如下,请大家帮忙看下
public static string GetHtml(string URL, string strId, string strPassword)
{
string postData = "c=login&loginName=" + strId;
postData += ("&password=" + strPassword );
byte[] data = Encoding.UTF8.GetBytes(postData);
CookieCollection ckclReturn = new CookieCollection();
CookieContainer cc = new CookieContainer();
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
myRequest.CookieContainer = cc;
myRequest.ProtocolVersion = HttpVersion.Version11;
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 663; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727)";
myRequest.ContentLength = data.Length; myRequest.Method = "post";
myRequest.Accept = "*/*";
myRequest.KeepAlive = true; myRequest.ServicePoint.Expect100Continue = false;
Stream newStream = myRequest.GetRequestStream(); newStream.Write(data, 0, data.Length);// 提交请求数据
newStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
return (content);
}private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = GetHtml("http://youxi.baidu.com/ajax_user_login.xhtml", "用户名", "密码");
}
本人在做网站模拟登陆,发现登陆的时候,发送变成了2个数据包,可能是这方面原因造成我无法登陆,登陆的时候,说参数异常,现代码如下,请大家帮忙看下
public static string GetHtml(string URL, string strId, string strPassword)
{
string postData = "c=login&loginName=" + strId;
postData += ("&password=" + strPassword );
byte[] data = Encoding.UTF8.GetBytes(postData);
CookieCollection ckclReturn = new CookieCollection();
CookieContainer cc = new CookieContainer();
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
myRequest.CookieContainer = cc;
myRequest.ProtocolVersion = HttpVersion.Version11;
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 663; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727)";
myRequest.ContentLength = data.Length; myRequest.Method = "post";
myRequest.Accept = "*/*";
myRequest.KeepAlive = true; myRequest.ServicePoint.Expect100Continue = false;
Stream newStream = myRequest.GetRequestStream(); newStream.Write(data, 0, data.Length);// 提交请求数据
newStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
return (content);
}private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = GetHtml("http://youxi.baidu.com/ajax_user_login.xhtml", "用户名", "密码");
}
我也一直在研究自动登录 这是以前做的httpwebrequest登录wordpress
就是我已经登陆成功了,返回的值是{"result":"1","msg":"用户名密码正确","loginAfter":[]},是登陆百度的,但是现在需要跳转其他页面,就需要COOKIES这个值,COOKIES里有个BUDSS这个值,无法获取到,请做过百度登陆的大神帮忙解决下,这个值是生成的,还是抓取的,我看了几个页面,发现就是通过http://youxi.baidu.com/v2/api/?getapi&class=login&tangram=true&callback=initBDPassApi&_=1348037438558这个页面以后就开始有了BDUSS的值,但是抓取COOKIES,也没有获得,不知道是怎么生成的