vb.net WebClient.DownloadString失败,发生异常

时间:2019-03-09 17:12:52

标签: vb.net visual-studio-2017 webclient

我正在使用VB.Net中的VS 2017编码程序。该程序使用Net.WebClient.DownloadString下载网页,然后解析数据。在一年或一年以上的时间内运行良好,然后有一天我开始下载页面时出现异常。

ex.Message是:'基础连接已关闭:发送中发生意外错误。

ex.InnerException.Message为:'无法将数据写入传输连接:由于未连接套接字,并且(在使用sendto调用在数据报套接字上发送时)否,不允许发送或接收数据的请求地址已提供。'

我在此位置的另外两台PC上和另一位置的另一台PC上安装了VS 2017。他们都继续毫无例外地运行代码。这只是此PC上的问题。

下面的代码(我更改了网址,但对于任何有效的URL都失败了。)

有什么想法为什么只能在我的主PC上失败?

Public Function DownloadData() As Boolean

    Dim strURL As String = "https://www.google.com/"
    Dim strOutput As String

    Try
        Using WC As New Net.WebClient

            strOutput = WC.DownloadString(strURL)

            If strOutput.Length > 0 Then
                If ParseData(strOutput) = True Then
                    Return True
                End If
            Else
                Return False
            End If
        End Using

    Catch ex As Exception
        MessageBox.Show(ex.InnerException.Message, "Error")

    End Try

End Function

0 个答案:

没有答案
相关问题