zoukankan      html  css  js  c++  java
  • 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?

    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.

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

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

    [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.

  • 相关阅读:
    SRM 588 D2 L3:GameInDarknessDiv2,DFS
    [置顶] ProDinner体验
    [置顶] 强制访问控制内核模块Smack
    Java小项目--坦克大战(version1.0)
    utf-8-validation
    is-subsequence
    perfect-rectangle
    find-the-difference
    longest-absolute-file-path
    first-unique-character-in-a-string
  • 原文地址:https://www.cnblogs.com/zitjubiz/p/9694634.html
Copyright © 2011-2022 走看看