[英]Vb.Net Get Resposnes form called API using WebClient
目前,我正在開發一個 web 服務,該服務將被稱為 JSON 之后。 它工作正常,我的記錄發布沒有任何問題。
我的問題是顯示響應。 我使用 UploadData 發送.. 我需要使用下載數據來接收嗎? 如果我需要在 MessageBox 的響應中顯示怎么辦。
請注意,我也期待 JSON 格式的響應。 至少讓我知道這個概念? 首先我想,我需要接收響應並且我會反序列化它。
這是我當前的代碼。 工作正常,但我無法顯示響應。
Public Function postData(ByVal JsonBody As String) As Boolean
Dim webClient As New WebClient()
Dim resByte As Byte()
Dim resString As String
Dim reqString() As Byte
Try
Dim APIusername As String = "XXXXX"
Dim APIPassword As String = "XXXXX"
webClient.Headers("content-type") = "application/json"
webClient.Credentials = New System.Net.NetworkCredential(APIusername, APIPassword)
reqString = Encoding.Default.GetBytes(JsonBody)
resByte = webClient.UploadData(Me.urlToPost, "post", reqString)
resString = Encoding.Default.GetString(resByte)
Console.WriteLine(resString)
' Here I need to show the responses
webClient.Dispose()
Return True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return False
End Function
我使用了 http 請求而不是 web 客戶端,它可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.