C# C/S程序请求网页地址,并获取返回数据代码
string url = "http://www.baidu.com/";
System.Net.HttpWebRequest webrequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();//请求连接,并反回数据
Stream stream = webresponse.GetResponseStream();//把返回数据转换成流文件
byte[] rsByte = new Byte[webresponse.ContentLength]; //把流文件转换为字节数组
try
{
stream.Read(rsByte, 0, (int)webresponse.ContentLength);
string HTML=System.Text.Encoding.Default.GetString(rsByte, 0, rsByte.Length).ToString();
}
catch (Exception exp)
{
exp.ToString();
}
C# C/S程序请求网页地址,并获取返回数据代码
最新推荐文章于 2024-05-21 17:28:00 发布