【发布时间】:2020-03-12 08:57:13
【问题描述】:
我开发了一个 Angular 8 Spring boot 2 应用程序
我尝试从 Angular 服务发送 POST 请求,但出现错误 415 Unsupported Media Type
服务角度
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
const options = { headers: headers };
return this.http.post<Search>('/api/produitimmobilier/all', search, options).pipe(.......
我尝试了我的 spring boot 2 控制器的 2 个配置:
@RequestMapping(value = "/produitimmobilier/all",
method = RequestMethod.POST,consumes ="application/json")
@ResponseBody
public Search findAll(@RequestBody Search search){
和
@RequestMapping(value = "/produitimmobilier/all",
method = RequestMethod.POST,consumes = {"text/plain;charset=UTF-8", MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public Search findAll(@RequestBody Search search){
但我有同样的错误。你能帮帮我吗?
【问题讨论】:
-
在 Postman 或 Swagger 中测试是否能按预期工作?
标签: angular spring-boot post angular-httpclient