1

私はVisual Studio 2013を使用しています...

Api コントローラー メソッドに問題があります。

HTTPGETHTTPPUT[FromUri]およびの違いを理解しています[FromBody].

私は単純なメソッドを持っており、すべての組み合わせをテストしています。

私が走るとき

http://localhost:62536/api/Controller/Method/10

I Got HTTP 404 error はこの例です

[HttpPut]
public string Method([FromUri] int a)
{
return "";
}

[HttpPut]
public string Method( int a)
{
return "";
}

[HttpGet]
public string Method([FromUri] int a)
{
return "";
}

[HttpGet]
public string Method( int a)
{
return "";
}

HTTP 405 エラーが発生した場合の例は次のとおりです

 [HttpPut]
         public string Method([FromBody] int a)
         {
         }

NO エラーですが、パラメーターaは 0 です..

 [HttpGet]
         public string Method([FromBody] int a)
         {
             return a.ToString();
         }

つまり.. [HttpPut] を使用したり、定義されていないか [FromUri] として定義されていないパラメーターを使用したりしても機能しません。

[HttpGet] と [FromBody] でのみ機能しますが、パラメーターは null です。

私の WebApiConfig は次のようになります

 public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
           
        }

なぜ機能しないのですか?

4

1 に答える 1