I know there are similar posts regarding calling an HttpPost method but nothing I've read/implemented has worked for me. I'm simply trying to do a POST call but the response is always null for some reason. I'm new to web development and ASP.
Here's my WebClient code:
using (WebClient webClient = new WebClient())
{
webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
var dataToSend = "=testingu";
var response = webClient.UploadString("http://localhost:5000/core/test", "POST", dataToSend);
Console.WriteLine("Response is: " + response);
}
and here's my HttpPost code:
[HttpPost("/core/test")]
public string PostObj([FromBody]dynamic input)
{
string result = "";
if (input == null)
System.Console.WriteLine("Input is null.");
else
System.Console.WriteLine("Input is not null: " + input);
return result;
}
Whenever PostObj is called, the "Input is null" line is always executed when I'm expecting to see "Input is not null: testingu" printed. It seems like my WebClient code is sound, but I'm pretty new to this so any help is appreciated.