私は MVC-4 Web-API サーバーを持っています。それと通信するには、HTTP クライアントを「手動で」(TCP 経由で) 作成する必要があります。
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)
{
}
}
簡単なクライアントを作成し、サーバーのコントローラーのメソッドにブレークポイントを設定しました。クライアントでは、これを送信します:
GET /api/updateunitdetails HTTP/1.1
Host: localhost:58743
Content-Type: */*
Content-Length: 10
home=sweet
そしてそれは機能します(デバッガーはGet
メソッドで停止します)。しかし、に変更GET
するとPOST
、そうではありません。さらに、リクエストを発行するたびにPOST
、Visual Studio コンソールに次のメッセージが表示されます。
A first chance exception of type 'System.InvalidOperationException' occurred in System.Web.Http.dll
何が恋しいですか?