簡體   English   中英

無法使用 C#.Net Framework 中的參數調用 HttpGet 方法

[英]Cannot call HttpGet method with parameters in C# .Net Framework

我在調用帶參數的 HttpGet 方法時遇到問題。 我在.Net Framework 4.7.2 中工作。 我正在使用 Advanced REST 客戶端來測試我的方法。 當我調用一個沒有參數的方法時,它工作得很好,但是當我想調用一個有參數的方法時,我不能。 我犯的錯誤在哪里? 這是我的兩種方法。

[HttpGet]
    [Route("action1")]
    public IHttpActionResult action1()
    {
        return Ok("blabla");
    }

    [HttpGet]
    [Route("action2/{parameter}")]
    public IHttpActionResult action2(string parameter)
    {
        return Ok(parameter);
    }

這就是我所說的第二種方法。 正如我所說,第一個工作得很好。高級 Rest 客戶端使用

這是我不斷收到的消息: { "Message": "No HTTP resource was found that matches the request URI 'https://localhost:44338/api/login/action2/?parameter="blabla"'.", "MessageDetail": "No action was found on the controller 'Login' that matches the request." } { "Message": "No HTTP resource was found that matches the request URI 'https://localhost:44338/api/login/action2/?parameter="blabla"'.", "MessageDetail": "No action was found on the controller 'Login' that matches the request." }

該操作正在使用一個路由參數,該參數神奇地將 url 字符串(不是查詢參數)的一部分與操作參數匹配。

您應該將 Postman 中的 URL 更改為https://localhost:44338/api/login/action2/blabla

或者您可以從 Route 屬性中刪除{parameter}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM