Search code examples
c#web-servicesrestrest-client

Test REST Get WS with RESTClient : FromBody always null


This is my Ws :

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

    return Ok("blah");
}

I try to test it with FireFox addOn RestClient, choosing GET, with the good url, and in body i have "test", so my filePath param should contains "test", but it's always null. Where's the problem?


Solution

  • GET requests do not have a body so you need to remove the [FromBody] attribute

    [HttpGet]
    [Route("api/Schema/convertDwgEnJson")]
    public IHttpActionResult Get(string filePath)
    {
        //TODO
    
        return Ok("blah");
    }
    

    You need to include it in the url if you are doing a GET

    api/Schema/convertDwgEnJson?filePath=test
    

    If you need to send it in the Body then You need to do a POST or PUT request.

    [HttpPost]
    [Route("api/Schema/convertDwgEnJson")]
    public IHttpActionResult Post(string filePath)
    {
        //TODO
    
        return Ok("blah");
    }