httpwebrequest提交问题
本人在做模拟登陆,现在发现登陆的时候,老说我参数异常,我测试过后,发现我发送的数据包是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", "用户名", "密码");
}