HttpWebRequest.GetResponse() hangs the second time it is called

后端 未结 5 749
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 00:43

I\'m trying to fetch a series of files via HTTP, using HttpWebRequest. The first request goes through fine, but the second time through the same code GetResponse() hangs and

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 01:39

    'You need to initialize the webrequest and webresponse objects with a valid URI:

            Dim request As WebRequest = WebRequest.Create("http://google.com")
            Dim response As WebResponse = request.GetResponse()
    
            Function UrlExists(ByVal URL As String) As Boolean
                Try
                    request = WebRequest.Create(URL)
                    response = request.GetResponse()
                Catch ex As Exception
                    Return False
                Finally
                    response.Close()
                End Try
                Return True
            End Function
    

提交回复
热议问题