Below is the request that I want to send. How do I do this via HttpClient? The endpoint is created in WebAPI.
The endpoint code is something like this:
public string Post([FromBody]string sentence) {
return sentence;
}
This is what I am trying:
public async static void getComponents(string inputString) {
using (var client = new HttpClient()) {
// New code:
Console.WriteLine("sadsadsad");
client.BaseAddress = new Uri("http://localhost:2500/");
client.DefaultRequestHeaders.Accept.Clear();
var abc = client.PostAsync("/api/image", new StringContent(inputString, "application/json")).Result;
Console.WriteLine(abc.ToString());
}
}
The request is received on the server side, but the parameter is null. I get 415 Unsupported Media Type when I try adding application/json just to the DefaultRequestHeaders.