A. Gladkiy
A. Gladkiy

Reputation: 3450

How to get complex data from [FromBody] attribute in WebAPI

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();
    }

Upvotes: 2

Views: 3151

Answers (1)

Alexander Kobelev
Alexander Kobelev

Reputation: 1379

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

enter image description here

Upvotes: 2

Related Questions