【问题标题】:How do I correctly call the endpoint below?如何正确调用下面的端点?
【发布时间】:2018-10-12 02:45:13
【问题描述】:

当 searchItem 参数有“+”等特殊字符时,该特殊字符在到达端点时会被省略。 我尝试对参数进行 URL 编码,但这也会导致 404 错误。 请帮忙

    [HttpGet]
    [Route("search/{searchItem}")]
    public HttpResponseMessage Search(string searchItem)
    {

        return Request.CreateResponse(HttpStatusCode.OK);
    }

【问题讨论】:

    标签: c# asp.net-mvc asp.net-web-api urlencode urldecode


    【解决方案1】:

    第一个想法是创建绑定模型并从body中获取值。

    [HttpGet]
    [Route("search")]
    public HttpResponseMessage Search([FromBody] SearchItemDto model)
    {
    
        return Request.CreateResponse(HttpStatusCode.OK);
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-25
      • 1970-01-01
      • 2017-09-04
      • 2018-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      相关资源
      最近更新 更多