I have used the following code before without any issues. Now I am getting :
PostAsync is not a member of HttpClient
I have made sure that the relevant references are present, and that all Imports are in place (Imports System.Net.Http).
I am using .Net Framework 4.5, I have also tried 4.5.1 but to no avail.
Public Shared Async Function PostTrx(ByVal baseURI As String, ByVal code As String, ByVal account As String, ByVal serial As String, ByVal dest As String) As Task(Of String)
Dim client As HttpClient = New HttpClient()
Dim content = New FormUrlEncodedContent({New KeyValuePair(Of String, String)("response", code), New KeyValuePair(Of String, String)("account", account), New KeyValuePair(Of String, String)("sn", serial), New KeyValuePair(Of String, String)("mode", dest)})
Dim response = Await client.PostAsync(baseURI, content)
Dim stringContent = Await response.Content.ReadAsStringAsync()
Return stringContent
End Function
答案 0 :(得分:0)
我能够通过添加“ Http”来解决此问题。在HttpClient之前,因此您的代码应类似于:
Public Shared Async Function PostTrx(ByVal baseURI As String, ByVal code As String, ByVal account As String, ByVal serial As String, ByVal dest As String) As Task(Of String)
Dim client As Http.HttpClient = New Http.HttpClient()
Dim content = New FormUrlEncodedContent({New KeyValuePair(Of String, String)("response", code), New KeyValuePair(Of String, String)("account", account), New KeyValuePair(Of String, String)("sn", serial), New KeyValuePair(Of String, String)("mode", dest)})
Dim response = Await client.PostAsync(baseURI, content)
Dim stringContent = Await response.Content.ReadAsStringAsync()
Return stringContent
End Function
希望这会有所帮助!