在一个角7应用程序中,我调用一个服务:
this.messageService.send(model).pipe(
catchError(err => {
console.log('Error:', err);
return err;
}),
map((response: Response) => {
console.log(response);
})
);
服务方法调用API:
public send(model: Model): Observable<Response> {
const headers: HttpHeaders = new HttpHeaders();
headers.set('Content-Type', 'application/x-www-form-urlencoded');
console.log(model);
return this.httpClient.post<Response>>(`send`, model, { headers: headers });
}
当我执行model
时,我能够在控制台上看到console.log(model);
但是,我在API上的断点不会触发,catchError
中也不会出现任何错误。
API操作是ASP.NET Core2.2。如下所示:
[HttpPost("send")]
public async Task<IActionResult> Send([FromBody]Model model) {
return Ok();
}
注意事项
在同一个应用程序中,我可以使用httpClient
和get
方法,而不存在任何问题。
不知道我错过了什么。有什么想法吗?
更新
我将角服务代码更改为:
public send(model: Model): Observable<Response>> {
const headers: HttpHeaders = new HttpHeaders();
headers.set('Content-Type', 'application/json');
console.log(model);
return this.httpClient.post<Response>>(`send`, JSON.stringify(model), { headers: headers });
}
还是不起作用。
这是一个角度问题,因为我刚刚发布的JSon数据与邮递员。
它使用邮递员工作,没有任何形式的认证/授权。
发布于 2019-02-21 09:18:39
尝试查看visual studio上的输出窗口。也许有一些关于这个问题的信息。验证控制器是否有AthorizationAttribute。验证内容-类型“、”application/x-www-form-urlencoded“,尝试将其更改为”Content“:”application/json“
https://stackoverflow.com/questions/54812383
复制相似问题