|
1金钱
如何获得404页面的源代码啊 我用的是httpwebrequest
public static string GetHttpCode(string url, string path)
{
string TestUrl = "http://" + url + path;
try
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(TestUrl);
myReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19";
myReq.Method = "GET";
myReq.Accept = "*/*";
myReq.KeepAlive = true;
myReq.Timeout = 20000;
HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
StreamReader readerOfStream = new StreamReader(response.GetResponseStream(), Encoding.Default);
page_text = readerOfStream.ReadToEnd();
readerOfStream.Close();
response.Close();
return page_text;
}
}
catch
{
return "";
}
return "";
}
如何页面真是存在,返回头是200,就不会进入catch,如果不存在,就是404,就会进入catch里面 我如何得到404页面的源代码??????、求高手指教
|
|