我尝试在浏览器中查看我的 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;
}
}
Testing
方法顶部添加[HttpGet]
[HttpGet]
public HttpResponseMessage Testing()
或在方法名称处添加Get
public HttpResponseMessage GetTesting()
然后它应该可以通过 http://localhost:2797/api/Country/Testing