I am new to WebAPI and trying to learn it. I have an WebAPI controller to which I am trying to POST a string using WebClient from my Unit Test.
I am posting a string to my WebAPI using following code below.
using (var client = new WebClient())
{
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
var result = client.UploadString(_webapiUrl, "POST", "hello");
}
Here is my controller.
[HttpPost]
public byte[] Post(string value)
{
// Do something with value
}
I can hit a break point on my controller, but it doesn't seem to POST any string and I always get NULL value. What should I do to get the value ?
Thanks