Http 415不支持的媒体类型错误与JSON POST

时间:2015-11-26 12:59:47

标签: spring rest spring-mvc http-error

我正在尝试执行项目 https://github.com/bava/springrest-book/tree/master/Chapter4/final/quick-poll-ch4-final

我的控制器是 https://github.com/bava/springrest-book/blob/master/Chapter4/final/quick-poll-ch4-final/src/main/java/com/apress/controller/PollController.java

我所做的只是改变是使用Lombok(暂时不在Poll类中)

@ToString   
@Entity
public class Option {
    @Id
    @GeneratedValue
    @Column(name="OPTION_ID")
    @Getter 
    @Setter
    private Long id;

    @Column(name="OPTION_VALUE")
    @Getter 
    @Setter
    private String value;
}

我收到错误

{"timestamp":1448542212469,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'text/plain;charset=UTF-8' not supported","path":"/polls"}

发送POST请求时

{
    "question": "Who will win SuperBowl this year?",
    "options": [
                       {"value": "New England Patriots"},
                       {"value": "Seattle Seahawks"},
                       {"value": "Green Bay Packers"},
                       {"value": "Denver Broncos"}]
}

不确定我做错了什么 enter image description here 注意:Get工作正常(暂时只能尝试0条目)

1 个答案:

答案 0 :(得分:3)

您必须为正在进行的请求指定Content-type,如下所示。

enter image description here