HttpClient
The typical way to access a REST API is using the HttpClient
. Create a HttpClient
object. Pass in request headers. Call the PostAsync
method with the URL and the request body. Use await
keyword to wait for the response. Get the message as a JSON string. Use JavaScriptSerializer
to convert the JSON to a C# object.
async Task<int> GetResultUsingHttpClient() { Uri uri = new Uri("http://localhost/api/Algebra /DoAlgebra?num1=3&num2=4");…