单纯用程序来登录 远程网页,可以用 以下例子,不过就像楼上所说,无法跨越 验证码 的障碍。
Uri uri = new Uri("http://www.);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.Timeout = 2000;
request.KeepAlive = false;
StringBuilder sb = new StringBuilder(250);
sb.Append("login=");
//用户名,要和远程页面的控件名一致,或者与地址栏中的变量名一致
sb.Append(sloginid);
sb.Append("&pwd=");
//密码
sb.Append(spwd);
byte[] sendbyte = Encoding.ASCII.GetBytes(sb.ToString());
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = sendbyte.Length;
Stream sendStream = request.GetRequestStream();
if (sendStream.CanWrite)
{
sendStream.Write(sendbyte, 0, sendbyte.Length);
}
sendStream.Close();
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new (responseStream);
string srcString = reader.ReadToEnd();
//srcString 就是网页源码,可对源码进行分析,获取需要的内容。