简体   繁体   English

在REST API中发布帖子时出现不受支持的媒体类型错误

[英]Unsupported Media Type error when making a post into a REST API

I have a REST API built with Spring-boot . 我有一个使用Spring-boot构建的REST API。 I want to perform a post request using postman, but I'm getting the error "Unsupported Media Type". 我想使用邮递员执行发布请求,但出现错误“不支持的媒体类型”。 I guess is related with the JSON, which should be bad form, but I can't imagine why. 我猜想与JSON有关,这应该是错误的形式,但我无法想象为什么。 This is my JSON object: 这是我的JSON对象:

{
    "id": 6,
    "name": "Jonh",
    "pass": "464d83f2a73cc7068632fb46cbb0214538dec819",
    "typeOfSubscription": "TRIAL_VERSION",
    "partiesRemainingThisMonth": 1,
    "subscriptionEndDate": 2458078,
    "parties": []
}

And this are the variables that I have defined of the object on the API: 这是我在API上为对象定义的变量:

private Integer id;
private String name;
private String pass;
private TypeOfSubscription typeOfSubscription;
private Integer partiesRemainingThisMonth;
private Date subscriptionEndDate;
private List<Party> parties;

TypeOfSubscription is a enum with the following values: TypeOfSubscription是一个具有以下值的枚举:

NO_SUBSCRIPTION(0, 0, 0),
TRIAL_VERSION(1, 1, 1),
ONE_MONTH(2, 3, 1),
THREE_MONTHS(3, 5, 3),
SIX_MONTHS(4, Integer.MAX_VALUE, 6);

private Integer id;
private Integer partiesPerMonth;
private Integer subscriptionMonths;

I don't find out why it's failing because the JSON looks good built. 我不知道为什么它会失败,因为JSON看起来不错。 I suspect that the enum is involved, or maybe the date (I'm using Julian format). 我怀疑涉及枚举或日期(我使用的是朱利安格式)。

Thanks in advance! 提前致谢!

It does not appear that you have any headers set. 似乎没有设置任何标题。 You'll want to set the header: 您将要设置标题:

Content-Type: application/json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM