Uri uri = new Uri("http://localhost:3501/Default.aspx");
HttpWebRequest hwReq = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse hwRes = (HttpWebResponse)hwReq.GetResponse();
hwReq.Method = "GET";
hwReq.KeepAlive = false;
StreamReader reader = new StreamReader(hwRes.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
string source= reader.ReadToEnd(); 调式了一下发现hwRes.ContentLength=532,但获取的源码(source)为空,hwRes.GetResponseStream()一句执行的过程中有异常+Length “hwRes.GetResponseStream().Length”引发了“System.NotSupportedException”类型的异常 long {System.NotSupportedException},怎么改正能获得源码
HttpWebRequest hwReq = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse hwRes = (HttpWebResponse)hwReq.GetResponse();
hwReq.Method = "GET";
hwReq.KeepAlive = false;
StreamReader reader = new StreamReader(hwRes.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
string source= reader.ReadToEnd(); 调式了一下发现hwRes.ContentLength=532,但获取的源码(source)为空,hwRes.GetResponseStream()一句执行的过程中有异常+Length “hwRes.GetResponseStream().Length”引发了“System.NotSupportedException”类型的异常 long {System.NotSupportedException},怎么改正能获得源码
string xmlResult = wClient.DownloadString(url);
{
WebRequest request;
request = WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse response;
response = request.GetResponse();
return new StreamReader(response.GetResponseStream(), encoding).ReadToEnd();
}
hwReq.KeepAlive = false;试试
WebRequest Request = WebRequest.Create(url);
WebResponse Response = Request.GetResponse();
Stream resStream = Response.GetResponseStream(); StreamReader sr = new StreamReader(resStream, Encoding.UTF8);
rl = sr.ReadToEnd();