日期:2014-05-18 浏览次数:20818 次
HttpWebRequest request =(HttpWebRequest)(WebRequest.Create("http://www.sina.com.cn")); HttpWebResponse response =(HttpWebResponse)request.GetResponse(); if(response.StatusCode==HttpStatusCode.OK)//因为发送的是HTTP请求,所以可以强制转换成HttpWebResponse,用以获取它的StatusCode,这是表示请求状态 { Stream resStream =response.GetResponseStream(); StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default); string tempCode = sr.ReadToEnd(); resStream.Close(); sr.Close(); }