现在的位置: 首页 > 综合 > 正文

WebException 里的 StatusCode 并不可靠

2012年11月24日 ⁄ 综合 ⁄ 共 434字 ⁄ 字号 评论关闭

用以下代码判断了2.5万个域名,发现有一小部分结果有误。

  // 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

抱歉!评论已关闭.