简体   繁体   中英

Can't read request from postman in webapi

I have issue with my webapi. Im trying to send a post request to my webapi, but i always recive null value inside. How my body in postman request looks:

{
  "languageCharset" : 1045,
  "jsonBody" : [... WHOLE JSON HERE ...]
}

The request hits in good position, because i can debug it but always getting languageCharset = null and jsonString as empty string. This is how it looks like in c# code:

[...]
[HttpPost("")]
    [Route("")]
    public IActionResult Post([FromBody] RequestJSONFromBody requestJSONFromBody)
    {
      requestJSONFromBody = requestJSONFromBody;
      return new OkObjectResult(requestJSONFromBody);
    }
[...]

And RequestJSONFromBody:

using DatabaseConnection.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DatabaseConnection.Models
{
  public class RequestJSONFromBody
  {
    LanguageCharset languageCharset { get; set; }
    string jsonBody { get; set; }

  }
}

#Update 1

LanguageCharset Enum:

namespace DatabaseConnection.Types
{
  public enum LanguageCharset : short
  {
    pl = 1045,
    en = 1033,
    cs = 1029,
    ro = 1048,
    lv = 1062,
    de = 1031,
    lt = 1063,
    sk = 1051,
    tr = 1055,
    et = 1061,
    hu = 1038,
    ru = 1049,
    sl = 1060,
    rs = 2074,
    fi = 1035,
    no = 1044,
    at = 3079,
    fr = 1036,
    bg = 1026,
    da = 1030,
    gr = 1032,
    hr = 1050,
    it = 1040,
    nl = 1043,
    pt = 2070,
    sv = 1053,
    ua = 1058,
    be = 1059,
    es = 1034,
    mk = 1071,
    ka = 1087
  }
}

Postman POST path:

https://localhost:44397/api/translation/

You forgor public . And you send jsonString and receive jsonBody .

public class RequestJSONFromBody
{
   public LanguageCharset languageCharset { get; set; }
   public string jsonString { get; set; }
}

Postman:
json send Body->raw with JSON type

The problem was inside json (missing "). Question solved.

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