我尝试在浏览器中查看我的API控制器操作,但我似乎无法找到此endpiont解析的URL。我试过了:
http://localhost:2797/api/Country/Testing
http://localhost:2797/api/Country/GetTesting
我收到此错误:
<Error>
<Message>
The requested resource does not support http method 'GET'.
</Message>
</Error>
public class CountryController : ApiController
{
public HttpResponseMessage Testing()
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "value");
response.Content = new StringContent("hello", System.Text.Encoding.Unicode);
response.Headers.CacheControl = new CacheControlHeaderValue()
{
MaxAge = TimeSpan.FromMinutes(20)
};
return response;
}
}
答案 0 :(得分:0)
在[HttpGet]
方法
Testing
[HttpGet]
public HttpResponseMessage Testing()
或在方法名称
添加Get
public HttpResponseMessage GetTesting()
然后它应该可以访问
http://localhost:2797/api/Country/Testing