[英]Parsing XML in VB Generating Error
訪問此網址:“ https://api.randomsite.com/api1/1/auth.asp?username=x&password=x ”
如果用戶名和密碼正確,則應生成此xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<auth>
<authentication>successful</authentication>
<token>{3FE7472B-E43C-442A-BE6D-2643239F3204}</token>
<expires>20110307</expires>
</auth>
我正在嘗試使用以下代碼在VB.Net中訪問此文件:
Dim Login As XDocument = XDocument.Load("https://api.randomsite.com/api1/1/auth.asp?username=" + Username.Text + "&password=" + Password.Text)
Dim ResultofAuth As XElement = Login...<authentication>
If ResultofAuth = "successful" Then
Look Happy
Else
Look Sad because password probably incorrect!
End If
但是我正在生成一個錯誤:
Dim Login As XDocument = XDocument.Load("https://api.randomsite.com/api1/1/auth.asp?username=" + Username.Text + "&password=" + Password.Text)
該錯誤表明XDocument.Load不能用於外部xml文件。 是否有解決方法,可以使用Web上的xml文件?
使用Web客戶端將流下載到文檔,然后將流解析為XDocument類
Dim client As New WebClient()
AddHandler client.OpenReadCompleted,
Sub(s As Object, e As OpenReadCompletedEventArgs)
If e.Error Is Nothing Then
Dim doc = XDocument.Load(e.Result)
''TODO: Parse document
End If
End Sub
client.OpenReadAsync(New Uri("https://api.randomsite.com/api1/1/auth.asp?username=x&password=x", UriKind.Absolute))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.