简体   繁体   中英

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

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM