I want to POST data to WebAPI. Ideally I would just do:
http:www.myawesomesite.com?foo=bar
As a POST. But to my specific question, I am trying to use:
using(var webClient = new WebClient())
{
client.uploadString("http:www.myawesomesite.com", "POST", "foo=bar");
}
But that converts "foo=bar" to a bye array. Okay fine, I'm just trying to get it to work at this point.
My Web API controller looks like this:
[HttpPost]
public void MashPotatos(string foo)
{
potatoMasher.Mash(foo);
}
But I get The remote server returned an error: (404) Not Found.
First off, I thought WebAPI would automatically grock that data for me even if it was in the body of the request. But more importantly, I just want to be able to get it to work.
Ideally, I'd like to leave the WebAPI method in a form such that you can still invoke it by using a query string with a POST verb.