Vb.net 第二次尝试时Web请求获取响应失败

Vb.net 第二次尝试时Web请求获取响应失败,vb.net,httpwebrequest,getresponse,Vb.net,Httpwebrequest,Getresponse,我写了一个程序,在网站上搜索用户名,下载他们的html主页,找到下一页的链接,然后下载,依此类推。当我第一次运行程序时,用于搜索的get响应正常工作,用于下载所有html页面的get响应正常工作。但是,当我进行第二次搜索时,get响应将失败。我想可能是服务器在一段时间内只允许这么多搜索,但事实并非如此。当我关闭程序并再次运行时,一切又恢复正常。为什么除了最初的尝试之外,get响应在任何尝试中都会失败?您不能将web请求定义为新的,而且一旦web请求得到释放资源的响应,它们似乎无法关闭web请求。

我写了一个程序,在网站上搜索用户名,下载他们的html主页,找到下一页的链接,然后下载,依此类推。当我第一次运行程序时,用于搜索的get响应正常工作,用于下载所有html页面的get响应正常工作。但是,当我进行第二次搜索时,get响应将失败。我想可能是服务器在一段时间内只允许这么多搜索,但事实并非如此。当我关闭程序并再次运行时,一切又恢复正常。为什么除了最初的尝试之外,get响应在任何尝试中都会失败?您不能将web请求定义为新的,而且一旦web请求得到释放资源的响应,它们似乎无法关闭web请求。是因为我在后台工作人员中运行整个流程吗?我不知道怎么了。就在昨天,我总是可以做我想做的任何搜索

以下是我的搜索表单代码:

Private Sub FormSearch_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'if the user name is empty then initialize it
    If My.Settings.UserName = "" Then
        My.Settings.UserName = ""
    End If
    'if the current url is empty then initialize it
    If My.Settings.CurrentURL = "" Then
        My.Settings.CurrentURL = ""
    End If
    My.Settings.Save()
End Sub

Private Sub TextBoxUserName_TextChanged(sender As Object, e As EventArgs) Handles TextBoxUserName.TextChanged
    'if the text length of the text box is greater then zero
    If TextBoxUserName.TextLength > 0 Then
        'enable the search button
        ButtonSearch.Enabled = True
    Else
        'disable the search button and set focus on the text box
        ButtonSearch.Enabled = False
        TextBoxUserName.Focus()
    End If
End Sub

Private Sub ButtonSearch_Click(sender As Object, e As EventArgs) Handles ButtonSearch.Click
    'trim the text box of any spaces
    My.Settings.UserName = Trim(TextBoxUserName.Text)
    'if the user name is not equal to null
    If My.Settings.UserName <> "" Then
        'set the current url and test if it exists
        My.Settings.CurrentURL = "*url here*"
        If URLExists(My.Settings.CurrentURL) = True Then
            'save the settings
            My.Settings.Save()
            'return ok for the dialog result and close the form
            Me.DialogResult = Windows.Forms.DialogResult.OK
            Me.Close()
        Else 'cannot find the account
            'set the text box text to null and set focus on it
            TextBoxUserName.Text = ""
            TextBoxUserName.Focus()
        End If
    End If
End Sub

Private Function URLExists(url As String) As Boolean
    'create a new uri
    Dim uriURL As New Uri(url)
    'create a new web request of the uri
    Dim wrRequest As WebRequest = WebRequest.Create(uriURL)
    'set the web request timeout and method
    wrRequest.Timeout = 30000
    wrRequest.Method = "GET"
    'create a new web response
    Dim wrResponse As WebResponse
    Try
        'if the response succeeds then return true
        wrResponse = wrRequest.GetResponse
        Return True
    Catch ex As Exception 'the response failed so return false
        LabelMessage.Text = ex.Message
        Return False
    End Try
End Function

您需要显示您的代码,以便我们看到发生了什么问题是我没有关闭http web响应。现在它工作得很好。