0

我试图将我的外部 IP 放在标签中,所以我正在根据站点下载结果,但是当我通过 VPN 更改我的 IP 时,应用程序崩溃了,我相信这是因为它没有检查它是否正在获取绳子下来,他试过了。

在表单加载...

 If Label1.Text = LastIp Then

      Try

      Dim wc As New WebClient
      Label1.Text = wc.DownloadString("http://icanhazip.com/")

      If you can not then

      Label.Text = "Failed to get IP"

      End if

 End If

形式...

在此处输入图像描述

4

1 回答 1

0

您可以设置回调并指定文件的路径:

Dim wc As New WebClient
AddHandler wc.DownloadStringCompleted, AddressOf DownloadStringComplete
wc.DownloadStringAsync(New Uri("http://icanhazip.com/myfile.txt", UriKind.Absolute))

Private Sub DownloadStringComplete(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)

If Not IsNothing(e.Error) Then
    Label1.Text = e.Error.Message
ElseIf e.Cancelled Then
    Label1.Text = "canceled"
Else
    Label1.Text = e.Result
End If

End Sub
于 2017-12-03T14:05:09.973 回答