Maki a POST request to end point with the JSON payload

  Kiến thức lập trình

I have tried to Make a POST request to below end point with the following JSON payload using webforms but the Imports System.Net.Http namespace is not recognised in visual studio.

I have tried the following code to send sms

Class Program
Private Shared Async Function Main() As Task
Await SendJsonPayloadAsync()
End Function

Private Shared Async Function SendJsonPayloadAsync() As Task
    Dim apiUrl As String = "api_url"
    Dim jsonPayload As String = "{
        ""api_token"": ""3PDDDW...."",
        ""service_id"": 8731,
        ""sender_id"": ""TOS"",
        ""recipient"": [""255....""],
        ""message"": ""Hello World""

    Using client As HttpClient = New HttpClient()
        client.DefaultRequestHeaders.Add("Accept", "application/json")
        Dim content As StringContent = New StringContent(jsonPayload, Encoding.UTF8, "application/json")
        Dim response As HttpResponseMessage = Await client.PostAsync(apiUrl, content)
        If response.IsSuccessStatusCode Then
            Console.WriteLine("Request successfully sent!")
            Console.WriteLine($"Error: {response.StatusCode} - {response.ReasonPhrase}")
        End If
    End Using
End Function

End Class

New contributor

Choum Ahmed Khalifa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.