WebException 里的 StatusCode 并不可靠
时间:2010-09-19 来源:大力
用以下代码判断了2.5万个域名,发现有一小部分结果有误,比如测试 alibaba.com,得到的结果是404,其实它是301重定向。
// lots of other interesting code up here... catch (WebException wex) { // typical http error if (wex.Status == WebExceptionStatus.ProtocolError) { HttpWebResponse wrsp = (HttpWebResponse)wex.Response; throw new HttpException((int)wrsp.StatusCode, wrsp.StatusDescription); } else { throw new HttpException(500, wex.Message); } } // other interesting code goes down here...
GOOGLE到一个组件,测试很准,好像是收费的。 http://www.example-code.com/csharp/http_getStatus.asp
相关阅读 更多 +