swagger訪問api, TypeError: Failed to fetch

用swagger訪問https://localhost:44360/api/ads/1, 獲得的結果是 TypeError: Failed to fetch。
一開始覺得是後端代碼問題,檢查了很久,才發現是AdBlockPlus 把它當成廣告過濾了。



 
 

I have the following routing, which works on invokation /api/demo/info/34.後端

[Route("api/demo")]
public class Demo : Controller
{
    [HttpGet("Info/{x}")]
    public JsonResult GetInfos(string x) { ... }
}

Now, I'd like to pass a query string to select the ID, like so: /api/demo/info?x=34. How should I rephrase the attribute for that?api

When I tried entering [HttpGet("Info?x={x}")], the error message said that the question mark isn't valid there. I want to resolve it through the attributive approach and routing from the default mapping isn't an option.app

----------------------------------------------

All you should need to do is to declare your attribute as:post

[HttpGet("Info")]

while keeping the signature of the method as GetInfos(string x). In a GET route, WebAPI picks up all the parameters from the signature, and those which aren't present in the route can be passed as query string arguments as long as the name in the query string matches the name of the parameter.fetch

相關文章
相關標籤/搜索