Quote:
[HttpPost("{input}")]
You've bound the
input
parameter to the route. Whatever appears in the URL after
/GeneratorStatus/
will be the value of your
input
parameter.
Change your API method to:
[HttpPost]
public void PostString([FromBody] string input)
{
...
}
Change the calling code to specify the correct URL, and pass the content correctly:
string url = "https://localhost:44312/GeneratorStatus/";
HttpClient client = new HttpClient();
string input = JsonConvert.SerializeObject(jsonMessage);
var response = await client.PostAsync(url, new StringContent(input, Encoding.UTF8, "application/json"));
NB: If you upload the data as JSON, it needs to be valid JSON. If you want to post a string, it needs to be enclosed in double quotes and properly escaped. Just posting the raw string value won't work.
Model Binding in ASP.NET Core | Microsoft Docs[
^]
NB: You should also be using
IHttpClientFactory
to create the
HttpClient
instance, otherwise you risk running into problems under load:
Use IHttpClientFactory to implement resilient HTTP requests | Microsoft Docs[
^]