Uri uri = new Uri("http://open.elong.com/lowprice/elonglowprice.php?hotelid=50101015&format=xml&lang=cn");//创建uri对象,指定要请求到的地址
if (uri.Scheme.Equals(Uri.UriSchemeHttp))//验证uri是否以HTTP协议访问
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);//使用HttpWebRequest类的Create方法创建一个请求到uri的对象
request.Method = WebRequestMethods.Http.Get;//指定请求的方式Get方式
HttpWebResponse response = (HttpWebResponse)request.GetResponse();//获取该请求所响应回来的资源,并强转为HttpWebResponse响应
StreamReader reader = new StreamReader(response.GetResponseStream());//获取该响应对象的可读流
string str = reader.ReadToEnd();//将流文本读取完成并赋值给str
response.Close();//关闭响应
}
if (uri.Scheme.Equals(Uri.UriSchemeHttp))//验证uri是否以HTTP协议访问
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);//使用HttpWebRequest类的Create方法创建一个请求到uri的对象
request.Method = WebRequestMethods.Http.Get;//指定请求的方式Get方式
HttpWebResponse response = (HttpWebResponse)request.GetResponse();//获取该请求所响应回来的资源,并强转为HttpWebResponse响应
StreamReader reader = new StreamReader(response.GetResponseStream());//获取该响应对象的可读流
string str = reader.ReadToEnd();//将流文本读取完成并赋值给str
response.Close();//关闭响应
}