我正在使用 angular 6 尝试使用 httpclient 发送一个 post 请求,但总是在服务器端接收 null body。
save( rules:RuleModel[]){
let _headers: HttpHeaders = new HttpHeaders({
'Content-Type': 'application/json; charset=utf-8'
});
return this._httpClient.post(AppConfig.BaseUrl,JSON.stringify(rules), {headers:_headers} ); }
和 API 函数
[HttpPost]
public List<Rule> AddTemplateTextRules( [FromBody]Rule[] Rules)
{
try
{
return RuleManager.AddRule(Rules);
}
catch (Exception e)
{
return null;
}
return null;
}
1 回答
要通过标准练习在 Angular 6 中发布帖子请求,您需要执行以下操作:
在服务类中:
在组件中:
然后在 ASP.NET 核心 API 控制器中:
希望它会对你有所帮助。