我在从响应中获取 HttpStatusCode 时遇到小问题。问题是当文件存在时我得到响应并且可以读取读取状态,但是当文件不存在时我看不到任何状态,即使我要求显示状态字符串。这是我的代码:
Dim urls As New List(Of String)
urls.Add("http://www.domain.com/test.php")
urls.Add("http://www.domain.com/test2.php")
urls.Add("http://www.domain.com/index.php")
For Each Url As String In urls
Dim response As HttpWebResponse = Nothing
Try
Dim request As HttpWebRequest = Net.HttpWebRequest.Create(Url)
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
request.Method = "GET"
response = request.GetResponse()
Catch webex As WebException
End Try
If response.StatusCode = HttpStatusCode.OK = True Then
MsgBox("File Url is correct: " & response.StatusCode.ToString)
ElseIf response.StatusCode = HttpStatusCode.NotFound = True Then
MsgBox("File Url is incorrect: " & Url)
Else
MsgBox(response.StatusCode.ToString)
End If
Next