0

私は 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

何が恋しいですか?

4

1 に答える 1

0

代わりにこれを使用してください:

POST /api/updateunitdetails HTTP/1.1
Host: localhost:58743

Content-Type: application/x-www-form-urlencoded


=sweet
于 2012-10-16T17:06:09.207 に答える