0

how can I set up an HTTP call in asp.net core mvc

$url = "https://prod-25.northeurope.logic.azure.com:443/..."
$parms = @{
    Uri = $url
    Method = 'post'
    ContentType = 'application/json'
    body = '{"recipient": "stefan.","body":"Test"}'

}
curl @parms
Stefan
  • 555
  • 5
  • 18
  • 1
    Does this answer your question? [How to make HTTP POST web request](https://stackoverflow.com/questions/4015324/how-to-make-http-post-web-request) – Adam Vincent Jan 21 '20 at 01:20
  • Does this solve your problem? https://learn.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client#sending-a-post-request-to-create-a-resource – Anduin Xue Jan 21 '20 at 07:01

1 Answers1

0

using

using System.Net.Http;

and your code will be

var url = "http://yoursite.com/Home/Insert";
var data = new {"recipient"= "stefan.", "body"="Test"};

using(var client = new HttpClient())
{
    var response = await client.PostAsJsonAsync(url, data);
    string responseContent = await response.Content.ReadAsStringAsync(); // only to see response as text ( debug perpose )

    var result = await ProcessedResult<TResult>(response); // cast it to TResult or any type that you expect to retrieve

}
Abdelrahman Gobarah
  • 1,544
  • 2
  • 12
  • 29