0

使用 javax.ws 我需要创建一个 POJO 对象,用于 POST 到服务。我必须发布的输入:

{
  "attributes": {
    "firstname": "John",
    "surname": "Doe",
    "birthyear": 1965
  }
}

我在下面的一个类中进行了设置,然后尝试使用以下方法调用它:

AuditTrail auditTrail = new AuditTrail(...);

 final Response response = app.target(MY_END_POINT)
.path(auditTrailPath.toString())
.request()
.post(Entity.json(auditTrail));

但我收到 HTTP 错误 204,无内容。

我这样做对吗?

    public class AuditTrail implements Serializable {

        @JsonProperty("attributes")
        public HashMap<String, String> attributes;

        public AuditTrail() {
            attributes = new HashMap<String, String>();
        }

        public AuditTrail(...) {

            attributes = new HashMap<String, String>();
// Set values here...
        }

        public HashMap<String, String> getAttributes() {
            return attributes;
        }

        public void setAttributes(HashMap<String, String> attributes) {
            this.attributes = attributes;
        }
    }
4

1 回答 1

0

你检查过你的服务器端吗?HTTP Status 204不是错误响应。它只是说“我已收到您的请求并成功处理它,但我不需要在响应的有效负载中发回给您”

参考https://httpstatuses.com/204

于 2016-06-26T23:16:24.057 回答