2

When I try send request "http://localhost:1234/api/case/create?signature=123456" from Postman (Google Extension) using "form-data" in body request, I get error:

"Message": "The request entity's media type 'multipart/form-data' is not supported for this resource.", "ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'Case' from content with media type 'multipart/form-data'.", "ExceptionType": "System.Net.Http.UnsupportedMediaTypeException".

My action:

    [Route("create")]
    public object Create([FromBody]Case newCase, string signature)
    {
        var member = _memberService.GetUserByToken(signature);
        if (member != null)
        {
            var caseId = _caseService.Add(newCase, member);

            return Ok(new { caseId });
        }

        return NotFound();
    }
Vnuuk
  • 6,177
  • 12
  • 40
  • 53
A. Gladkiy
  • 3,134
  • 5
  • 38
  • 82

1 Answers1

2

You should add header Content-Type: application/json in Postman

enter image description here

Alexander Kobelev
  • 1,379
  • 8
  • 14
  • 1
    I added header "Content-Type: application/json" in Postman, but then I get newCase = null. – A. Gladkiy Nov 06 '15 at 12:56
  • 1
    Try to use Raw data for POST. Look here http://stackoverflow.com/questions/19037636/web-api-2-post-request-simulation-in-postman-rest-client – Alexander Kobelev Nov 06 '15 at 13:00
  • Yes, it works with Raw data and Content-Type: application/json, thank you. But what's difference between form-data and raw? I'm going to write console app to test my api. – A. Gladkiy Nov 06 '15 at 13:08
  • 1
    Here https://www.getpostman.com/docs/requests you can find description about requests in postman. In a short: your web api action expects raw json data which then will be serialized to object. When you use form-data in postman the request is just like dictionary (key => value). – Alexander Kobelev Nov 06 '15 at 13:18