以下例子可以参考。
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=");
//发送两个参数,login,pwd
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就是想访问页面的,返回结果的网页源代码