设置json参数后得到400

时间:2016-07-14 19:47:44

标签: java json httpclient jsonobject

我正在尝试将以下json从JAVA发送到REST服务器

{  

   "image_url":"image",
   "job_fqn":"jobfqn",
   "ignore_volumes":true
}

我在HttpClient中设置如下

 JSONObject json = new JSONObject();
    json.put("image_url","image");
    json.put("job_fqn","jobfqn");
    json.put("ignore_volumes", "true");
    StringEntity params = new StringEntity(json.toString());
    post.setEntity(params);
    HttpResponse response = client.execute(post);

删除后,这给了我400,

json.put("ignore_volumes", "true");

这是一个有效的输入,不知道发生了什么。来自curl的json运行正常,只在java中失败

2 个答案:

答案 0 :(得分:0)

您是否尝试过drop X

json.put("ignore_volumes", true);设置为true而不是Boolean为真。

答案 1 :(得分:0)

尝试使用true作为布尔值而不是字符串。

String