0
我試圖開發一個API,允許在同一地址獲取和發佈請求。nohttp資源被發現匹配請求uri
public class DataController : ApiController
{
[HttpGet]
public DataResponse Foo()
{
return GetNext();
}
[HttpPost]
public void Foo(long p1, string p2)
{
SaveValue(p1,p2);
}
}
GET
工作正常。當調用POST
方法,我得到以下錯誤:
the requested resource does not support http method 'POST'
我WebApiConfig如下所示:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.EnableCors();
config.MapHttpAttributeRoutes();
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
config.Routes.MapHttpRoute(name: "DefaultApi", routeTemplate: "api/{controller}/{action}");
}
}
任何想法,我需要改變,以得到這個工作?
非常感謝,Ipsit。奇蹟般有效 :-) –