Hello.. I have some code migrating from VS Studio 2013 to VS Studio 2022. Seeing that WebReq has been deprecated. Working to migrate to HTTPClient. Seems that httpclient is async only, I am guessing here... My overall code is written to call a RoboCall server, wait for a success message then pass back to the caller, success or failure. I have been doing this with WebRequest. What I have found searching Google thus far is httpclient appears to be the replacement, but I seem to be having difficulty finding a way to call this function, have it wait for a success message then return to the caller. Hoping someone can point me in the right direction. Thanks // Jeff
Public Async Sub PostData(ByVal strMARCLId As String, ByVal strLogonId As String, ByVal strURI As String, ByVal strjsonPayload As String, ByVal strAuthString As String)
Using client As New HttpClient()
Try
'https://onp.vzwnet.com/notification-sms-n-voice/notification/notifyAll' \
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Basic", strAuthString)
client.Timeout = TimeSpan.FromSeconds(500)
Dim strContent As New StringContent(strjsonPayload, Encoding.UTF8, "application/json")
'------------------ Send the POST request
Dim response As HttpResponseMessage = Await client.PostAsync(strURI, strContent)
'------------------ Ensure the response was successful
response.EnsureSuccessStatusCode()
'------------------ Read and display the response body
Dim responseBody As String = Await response.Content.ReadAsStringAsync()
MsgBox("Response Status: " & response.StatusCode.ToString())
MsgBox("Response Body: " & responseBody)
'------------------
Dim strMessage As String = "Processsed API Request"
Dim strSubject As String = "Processsed API Request - " & response.StatusCode.ToString() & " / " & responseBody
GeneralMailerBLL.BLL__DataProcessor__GeneralMailer__Test_Mailert(strMARCLId, strLogonId, strSubject, strMessage)
client.Dispose()
Catch ex As Exception
MsgBox("Error: " & ex.Message)
Dim strMessage As String = "WARNING -- Unable to Process API Request - " & ex.Message & " / " & strURI & " / " & strjsonPayload & " / " & strAuthString
Dim strSubject As String = "WARNING -- Unable to Process API Request"
GeneralMailerBLL.BLL__DataProcessor__GeneralMailer__Test_Mailert(strMARCLId, strLogonId, strSubject, strMessage)
client.Dispose()
End Try
End Using