I have MVC-4 Web-API server, and I need to create HTTP client “by hand” (via TCP) to talk with it.
public class UpdateUnitDetailsController : ApiController
{
// GET api/updateunitdetails
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/updateunitdetails/5
public string Get(int id)
{
return "value";
}
// POST api/updateunitdetails
public void Post([FromBody]string value)
{
}
// POST api/updateunitdetails
public void Post()
{
}
// PUT api/updateunitdetails/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/updateunitdetails/5
public void Delete(int id)
{
}
}
I made a simple client and set breakpoints in the server’s controller’s methods. In the client, I send this:
GET /api/updateunitdetails HTTP/1.1
Host: localhost:58743
Content-Type: */*
Content-Length: 10
home=sweet
And it works (the debugger stops in the Get method). But if I change GET to POST, it doesn’t. Moreover, whenever I issue a POST request, I see in the Visual Studio Console this message:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Web.Http.dll
What do I miss ?
Use this instead: