记录特定状态代码之间的http web响应

时间:2013-12-09 03:03:00

标签: vb.net

我有以下代码来执行特定错误代码的某些任务

Using resp As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
    Select Case (resp.StatusCode)
        Case CType((resp.StatusCode >= HttpStatusCode.Accepted And resp.StatusCode <= HttpStatusCode.Ambiguous), HttpStatusCode)
            'do something
        Case CType((resp.StatusCode >= HttpStatusCode.BadRequest And resp.StatusCode < HttpStatusCode.InternalServerError), HttpStatusCode)
            'log something
        Case CType((resp.StatusCode > HttpStatusCode.InternalServerError), HttpStatusCode)
            'show something
    End Select

End Using

但是没有一个case语句被调用。

1 个答案:

答案 0 :(得分:0)

那么你的CType只是愚蠢的。 和其他代码一样。拿起一本书,上课,仔细阅读MSDN。

Using response As HttpWebResponse = request.GetResponse
  Select Case response.StatusCode
    Case Is <= HttpStatusCode.Accepted, Is <= HttpStatusCode.Ambiguous
      ...
  End Select
End Using