WebRequest 类代表要给某个URI发生信息的请求,URI作为参数传送给Create()方法.
WebResponse 类代表从服务器获取的数据.
调用WebRequest .GetResponse()方法实际上是把请求发送给Web服务器,创建一个Response对象,检查返回的数据.
可以得到一个代表数据的数据流,但是这里的数据流是使用WebResponse .GetResponseStream()方法获得的.
//网站地址 //编码规则
public static string getPartHtml(string url, string Encoding)
{
string result = url;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream(), System.Text.Encoding.GetEncoding(Encoding)))
{
result = sr.ReadToEnd();
sr.Close();
}
return result;
}