【问题标题】:error 415 Unsupported Media Type for an angular spring boot application角度弹簧启动应用程序的错误 415 不受支持的媒体类型
【发布时间】: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


【解决方案1】:

我发现了错误,搜索对象中有一个错误的映射,一个不正确的设置器。讨论结束。感谢您转发此帖

【讨论】:

    猜你喜欢
    • 2022-01-15
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 2018-07-25
    • 2016-09-09
    • 1970-01-01
    相关资源
    最近更新 更多