我想创建一个 post 方法来读取 Authorize.Net webhook 使用 VB.Net 发送的正文中的数据,我是 VB.Net 的新手,有人可以协助如何以 Post 类型的方法从正文中读取数据。
问问题
256 次
1 回答
1
要发送/接收 HTTP 请求/响应,通常您会使用 HttpClient 类(文档)。特别是在这种情况下,您将:
这是一个功能(未经测试),可以让您朝着正确的方向前进:
Imports System.Net
Imports System.Net.Http
Imports System.Threading.Tasks
Imports Newtonsoft.Json
Imports System.Text
'...
Private Async Function SendPost(url As String, data As Object) As Task(Of String)
Dim body = String.Empty
Using client = New HttpClient
Dim content As New StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json")
Dim response = Await client.PostAsync(url, content)
If (response.StatusCode = HttpStatusCode.OK) Then
body = Await response.Content.ReadAsStringAsync()
End If
End Using
Return body
End Function
于 2021-08-04T18:50:01.220 回答