我有一个有趣的问题...... 我正在搞乱链接检查程序,这是它的核心:
private static string CheckURL(string url)
{
string status = string.Empty;
string strProxyURL = "http://blah:1010";
string strNetworkUserName = "blahblahblah";
string strNetworkUserPassword = "blahblahblah";
string strNetworkUserDomain = "blahblah";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
WebProxy proxy = new System.Net.WebProxy(strProxyURL, false);
proxy.Credentials = new System.Net.NetworkCredential(strNetworkUserName, strNetworkUserPassword, strNetworkUserDomain);
request.Method = "HEAD";
request.Proxy = proxy;
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
status = response.StatusCode.ToString();
}
}
catch (WebException ex)
{
status = ex.Status.ToString();
}
return url + ";" + status;
}
...我从here捏了一把。
问题在于,对于我提供的大多数网址,我得到了一个“好”的网站。状态。但我有一个充当PDF查看器的页面,当用Fiddler检查时它似乎返回OK,但显示了' ServerProtocolViolation'作为我的检查员的状态。
我注意到这个网址的Fiddler结果有一个奇怪的地方,它有3个x-xss-protection和x-frame-options的实例,但是这不会停止它来自工作,是吗???
这是Fiddler数据:
HTTP/1.0 200 OK
Cache-Control: private
Pragma: public
Content-Length: 230070
Content-Type: application/pdf
Expires: Tue, 27 Jan 2015 17:17:46 GMT
Server: Microsoft-IIS/7.5
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
shortcut icon: href='http://www.jameshay.co.uk/favicon.ico' type='image/x-icon'
Content-Disposition: inline;filename=JamesHayDocJHMP0016Doc2931.pdf
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
X-AspNet-Version: 4.0.30319
X-UA-Compatible: IE=edge
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
Date: Tue, 27 Jan 2015 17:17:45 GMT
X-Cache: MISS from proxy-3_10
X-Cache: MISS from ClientSiteProxy
X-Cache-Lookup: MISS from ClientSiteProxy:3128
Connection: close
编辑(28/01 09:10 am): 使用Fiddler时,我用这个替换代理......
WebProxy proxy = new System.Net.WebProxy(" 127.0.0.1",8888);
DocumentView页面是唯一一个仍然通过后面的代码添加x-xss-protection和x-frame-options的页面,因为web.config文件也具有这些设置:
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=edge" />
<add name="X-XSS-Protection" value="1; mode=block" />
<add name="X-Frame-Options" value="DENY" />
</customHeaders>
</httpProtocol>
我认为导致重复的是......但重复是否真的会导致回复? (编辑结束)
那么我该怎样做才能让http请求回来&#39; OK&#39;在我的代码中,还是有其他方法来检查我可以使用的URL?
任何帮助,一如既往,非常感谢:)