【发布时间】:2021-04-06 11:55:36
【问题描述】:
我的 webapi 有问题。 我试图向我的 webapi 发送一个发布请求,但我总是在里面接收 null 值。 我在邮递员请求中的身体看起来如何:
{
"languageCharset" : 1045,
"jsonBody" : [... WHOLE JSON HERE ...]
}
请求命中正确,因为我可以调试它,但总是将 languageCharset = null 和 jsonString 作为空字符串。这就是它在 c# 代码中的样子:
[...]
[HttpPost("")]
[Route("")]
public IActionResult Post([FromBody] RequestJSONFromBody requestJSONFromBody)
{
requestJSONFromBody = requestJSONFromBody;
return new OkObjectResult(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; }
}
}
#更新 1
语言字符集枚举:
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
}
}
邮递员 POST 路径:
https://localhost:44397/api/translation/
【问题讨论】:
-
什么是
LanguageCharset- 枚举? -
@Genusatplay 我更新了更多细节
-
Postman 的其他详细信息是什么?内容类型等?如果您单击“代码”链接/按钮,选择 HTTP 作为语言,并使用它向您显示的内容更新您的问题,这可能会有所帮助。
-
其余都是默认的,没有任何改变
-
顺便说一句,您在请求正文中显示了“jsonString”,但类属性显示为“jsonBody”。
标签: c# .net-core postman webapi