简体   繁体   English

如何解决HTTP错误415-不支持的媒体类型

[英]How to get around HTTP Error 415 - Unsupported Media Type

I'm using Restet and I wanted to know if its possible if a ServerResource entity type is set, for example for this type of entity: 我正在使用Restet,想知道是否设置了ServerResource实体类型(例如,针对这种类型的实体)是否可行:

@XStreamAlias("role")
@ApiModel
public class Role {

    private String entityId;
    private String name;

    @ApiModelProperty(required = false, value = "")
    private List<String> aclRead;
    @ApiModelProperty(required = false, value = "")
    private List<String> acLWrite;
    @ApiModelProperty(required = false, value = "")
    private Boolean publicRead;
    @ApiModelProperty(required = false, value = "")
    private Boolean publicWrite;

    public String getEntityId() {
        return entityId;
    }

    public void setEntityId(String entityId) {
        this.entityId = entityId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getAclRead() {
        return aclRead;
    }

    public void setAclRead(List<String> aclRead) {
        this.aclRead = aclRead;
    }

    public List<String> getAcLWrite() {
        return acLWrite;
    }

    public void setAcLWrite(List<String> acLWrite) {
        this.acLWrite = acLWrite;
    }

    public Boolean getPublicRead() {
        return publicRead;
    }

    public void setPublicRead(Boolean publicRead) {
        this.publicRead = publicRead;
    }

    public Boolean getPublicWrite() {
        return publicWrite;
    }

    public void setPublicWrite(Boolean publicWrite) {
        this.publicWrite = publicWrite;
    }

}

How can we be able to POST without the need of passing all the fields, for this example we only wanted to pass the "name" from the Client Request, but doing that throws 415 - Unsupported Media Type 我们如何能够在无需传递所有字段的情况下进行POST,在此示例中,我们只想传递客户端请求中的“名称”,但这样做会抛出415 - Unsupported Media Type

In our client we only do pass this JSON 在我们的客户端中,我们仅传递此JSON

{
  "role" : {
     "name" : "AdminRole" 
  }
}

For the Get response of the Resource, the return type is Role also so the client will get all the fields, entityId, name, aclRead, aclWrite, publicRead and publicWrite through the Restlet marshalling. 对于“资源”的“获取”响应,返回类型也是“角色”,因此客户端将通过Restlet编组获取所有字段,entityId,name,aclRead,aclWrite,publicRead和publicWrite。

The problem we have is that we cannot POST. 我们的问题是我们无法发布。

In the post request, the json data should only consist of the the entity parameters without the entity name as root key. 在发布请求中,json数据应仅由实体参数组成,而没有实体名称作为根键。 So, your post request should look like this: 因此,您的发帖请求应如下所示:

{
    "name" : "AdminRole" 
}

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

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