这里发生的是我从数据库条目列表中获取API密钥数据,并将它们连接到将用作URL的字符串。然后,该URL用于通过返回XML文档的WebClient对象访问API端点。过去,这种方法运行良好,但在我使用API密钥访问没有适当权限的端点的情况下,服务器返回一个XML文档,说明此类和HTTP 403错误代码。无论出于何种原因,文档都被锁定在错误代码后面,并且无法通过e.Result的常用方法获得。尝试访问e.Result会抛出System.Reflection.TargetInvocationException。
还有另一种检索XML文档的方法吗?如果有帮助,这里是代码的缩减:
Public Sub DetermineValidKeys()
Dim AccountStatusURL As String = "https://api.eveonline.com/Account/AccountStatus.xml.aspx"
Try
Dim KeyID As String = Entries.Item(1).KeyID
Dim VCode As String = Entries.Item(1).VerificationCode
Dim URL As New Uri(AccountStatusURL + "?keyID=" + KeyID + "&vCode=" + VCode)
Dim web As New WebClient()
web.Proxy = Nothing
AddHandler web.DownloadStringCompleted, AddressOf EntryValidationCheck
web.DownloadStringAsync(URL)
Catch ex As Exception
End Try
End Sub
Public Sub EntryValidationCheck(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
Try
RichTextBox1.Text = e.Result
Catch ex As Exception
End Try
End Sub