1
我想構建一個接受字符串參數並返回字符串值的Web API,但我總是收到錯誤,請求的資源不支持HTTP方法GET
。我在堆棧溢出中搜索了一下,並添加了行[AcceptVerbs("GET")]
,但我仍然遇到了錯誤。有人能幫我嗎?Asp.net Web API所請求的資源不支持http方法'GET'
的Global.asax.cs文件
config.Routes.MapHttpRoute(
name: "sasRoute",
routeTemplate: "api/sas/{container}",
defaults: new
{
controller = "sas",
container = RouteParameter.Optional
}
);
控制器的方法
[Route("{container}")]
[AcceptVerbs("GET")]
[HttpGet]
public string GetContainerToken(string container)
{
return container;
}
您試圖使用哪個URL? –
@PaulAbbott的http://本地主機:52896/API/SAS /測試 –
你應該嘗試: [路線( 「/ API /移動/ {容器}」)] [HTTPGET] 公共字符串GetContainerToken(字符串容器) 返回容器; } –