简体   繁体   English

无法在 webapi 中读取来自 postman 的请求

[英]Can't read request from postman in webapi

I have issue with my webapi.我的 webapi 有问题。 Im trying to send a post request to my webapi, but i always recive null value inside.我试图向我的 webapi 发送一个发布请求,但我总是在里面收到 null 值。 How my body in postman request looks:我在 postman 请求中的身体看起来如何:

{
  "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.该请求在良好的 position 中命中,因为我可以调试它,但总是将 languageCharset = null 和 jsonString 作为空字符串。 This is how it looks like in c# code:这是 c# 代码中的样子:

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

And RequestJSONFromBody:和 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 #更新 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: Postman POST 路径:

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

You forgor public .你放弃public And you send jsonString and receive jsonBody .你发送jsonString并接收jsonBody

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

Postman: Postman:
json send Body->raw with JSON type json 发送 Body- Body->raw with JSON type

The problem was inside json (missing "). Question solved.问题出在 json 内部(缺少“)。问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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