我在使用如下代码来登陆网站,使用WebRequest.Create一个 https://dynamic..../loginAction.do?method=init System.IO.Stream outputStream = webRequest.GetRequestStream();
outputStream.Write(byteArray, 0, postData.Length);
之后使用HttpAnalyzer查看返回情况,从返回的内容来看,怎么返回的是填好登陆信息的登陆页面呢?也就是返回还是登陆页面,只是填好了登陆信息而已还想请家伙帮忙看看?
private void LOGIN_Click(object sender, EventArgs e)
{
string getname = NameTextBox.Text.ToString();
string getpwd = PwdTextBox.Text.ToString();
string getrandcoe = randcodebox.Text.ToString();
PostWebRequest(getname, getpwd, getrandcoe);
}
private void PostWebRequest(string name, string pswd, string randcode)
{
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((a, b, c, d) => { return true; });
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
string postData = "loginUser.user_name=" + name + "&ErrorFocus=&user.password=" + pswd + "&passwordErrorFocus=&randCode="+ randcode + "&randErrorFocus=";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化 CookieContainer cookieContainer = new CookieContainer(); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri("https://dynamic..../loginAction.do?method=init"));
webRequest.Headers.Add("accept-language", "zh-cn,zh;q=0.5");
webRequest.Headers.Add("accept-encoding", "gzip,deflate");
webRequest.Headers.Add("accept-charset", "GB2312,utf-8;q=0.7,*;q=0.7");
webRequest.Headers.Add("cache-control", "max-age=0");
webRequest.Headers.Add("keep-alive", "115");
webRequest.CookieContainer = cookieContainer;
webRequest.Referer = "https://dynamic...";
webRequest.Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1)";
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = postData.Length; // 提交请求数据
System.IO.Stream outputStream = webRequest.GetRequestStream();
outputStream.Write(byteArray, 0, postData.Length);
outputStream.Close();
try
{
// 接收返回的页面
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
if (response.Cookies.Count > 0)
cookieContainer.Add(response.Cookies);
string srcString = reader.ReadToEnd();
responseStream.Flush();
responseStream.Close();
response.Close();
}
catch (WebException ex)
{
MessageBox.Show(ex.Message);
}
}
outputStream.Write(byteArray, 0, postData.Length);
之后使用HttpAnalyzer查看返回情况,从返回的内容来看,怎么返回的是填好登陆信息的登陆页面呢?也就是返回还是登陆页面,只是填好了登陆信息而已还想请家伙帮忙看看?
private void LOGIN_Click(object sender, EventArgs e)
{
string getname = NameTextBox.Text.ToString();
string getpwd = PwdTextBox.Text.ToString();
string getrandcoe = randcodebox.Text.ToString();
PostWebRequest(getname, getpwd, getrandcoe);
}
private void PostWebRequest(string name, string pswd, string randcode)
{
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((a, b, c, d) => { return true; });
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
string postData = "loginUser.user_name=" + name + "&ErrorFocus=&user.password=" + pswd + "&passwordErrorFocus=&randCode="+ randcode + "&randErrorFocus=";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化 CookieContainer cookieContainer = new CookieContainer(); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri("https://dynamic..../loginAction.do?method=init"));
webRequest.Headers.Add("accept-language", "zh-cn,zh;q=0.5");
webRequest.Headers.Add("accept-encoding", "gzip,deflate");
webRequest.Headers.Add("accept-charset", "GB2312,utf-8;q=0.7,*;q=0.7");
webRequest.Headers.Add("cache-control", "max-age=0");
webRequest.Headers.Add("keep-alive", "115");
webRequest.CookieContainer = cookieContainer;
webRequest.Referer = "https://dynamic...";
webRequest.Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1)";
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = postData.Length; // 提交请求数据
System.IO.Stream outputStream = webRequest.GetRequestStream();
outputStream.Write(byteArray, 0, postData.Length);
outputStream.Close();
try
{
// 接收返回的页面
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
if (response.Cookies.Count > 0)
cookieContainer.Add(response.Cookies);
string srcString = reader.ReadToEnd();
responseStream.Flush();
responseStream.Close();
response.Close();
}
catch (WebException ex)
{
MessageBox.Show(ex.Message);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货