我是 vb.net 代码的新手。我必须从 vb.net 调用外部 API。我尝试了下面的代码,但它抛出了一个错误 - 将问题作为
<块引用>System.Threading.Tasks.k`1
Public Shared Async Function GetToken_saka() As Task(Of sakaweb)
Dim req As New HttpRequestMessage(HttpMethod.Post, "https://api.qa.se.com/token")
' req.Content = New FormUrlEncodedContent(New Dictionary < String, String > {
' {"client_id", "your client_id"},
' {"client_secret", "your client_secret"},
' {"grant_type", "client_credentials"}
'});
Dim dct As New Dictionary(Of String, String)
dct.Add("client_id", "your_client_id")
dct.Add("client_secret", "your_client_secret")
dct.Add("grant_type", "client_credentials")
Dim htc As New HttpClient
req.Content = New FormUrlEncodedContent(dct)
Dim response = Await htc.SendAsync(req)
response.EnsureSuccessStatusCode()
'Dim payload = JObject.Parse(Await response.Content.ReadAsStringAsync())
Dim payload = JsonConvert.DeserializeObject(response.ToString)
Dim token = payload.Value(Of String)("access_token")
Dim t1 As sakaweb = Nothing
Return t1
'Dim t1 As New Task("K")
'Return t1
End Function