使用 RESTClient 测试 REST 获取 WS:FromBody 始终为 null

Test REST Get WS with RESTClient : FromBody always null

这是我的 Ws :

[HttpGet]
[Route("api/Schema/convertDwgEnJson")]
public IHttpActionResult Get([FromBody]string filePath)
{
    //TODO

    return Ok("blah");
}

我尝试使用 FireFox addOn RestClient 对其进行测试,选择 GET,具有良好的 url,在正文中我有 "test",因此我的文件路径参数应包含 "test",但它始终为空。 问题出在哪里?

GET 请求没有正文,因此您需要删除 [FromBody] 属性

[HttpGet]
[Route("api/Schema/convertDwgEnJson")]
public IHttpActionResult Get(string filePath)
{
    //TODO

    return Ok("blah");
}

如果您要执行 GET

,则需要将其包含在 url 中
api/Schema/convertDwgEnJson?filePath=test

如果您需要在 Body 中发送它,那么您需要执行 POST 或 PUT 请求。

[HttpPost]
[Route("api/Schema/convertDwgEnJson")]
public IHttpActionResult Post(string filePath)
{
    //TODO

    return Ok("blah");
}