【问题标题】:HttpGet for accessing a url用于访问 url 的 HttpGet
【发布时间】:2021-11-14 17:40:19
【问题描述】:

我想从https://api.cqc.org.uk/public/v1/changes/location?page=1&perPage=1000000&startTimestamp=2021-09-18T02:33:20Z&endTimestamp=2021-09-19T02:33:20Z获取信息

我已经编写了以下语法,但它似乎不起作用

[HttpGet("changes/location{page}&{perPage}&{startTimestamp}&{endTimestamp}")]
        public async Task<ChangesDetailsVM>GetChange([FromRoute] string page, string perPage,  string startTimestamp, string endTimestamp)
        {
            return await _cqcService.GetChange(page, perPage, startTimestamp, endTimestamp);
        }

从 Postman 我收到以下错误:

对 cqc/changes/location1&1000&9/20/2021 8:57:53 AM&9/21/2021 8:57:53 AM 的请求失败,状态码 NotFound 响应:{ "statusCode": 404, "message": "Resource未找到“}”

有什么建议可以改善我的语法吗?

【问题讨论】:

  • changes/location{page}&amp;{perPage}&amp;{startTimestamp}&amp;{endTimestamp}改成changes/location,然后删除[fromRoute]

标签: c# http-get


【解决方案1】:

如果你使用路由可以这样写:

// route
[HttpGet("changes/location/{page}/{perPage}/{startTimestamp}/{endTimestamp}")]
// url
localhost:3055/changes/location/12/4534/2021-09-18T02:33:20/2021-09-19T02:33:20

但如果你想使用参数名称,请写下:

// route
   [HttpGet("changes/location")]

// url
localhost:3056/changes/location?page=121&perPage=1233&startTimestamp=2021-09-18T02:33:20&endTimestamp=2021-09-19T02:33:20

【讨论】:

    猜你喜欢
    • 2015-02-23
    • 2011-11-11
    • 2014-11-29
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多