user_mda user_mda - 4 months ago 7
JSON Question

Getting a 400 after setting json parameters

I am trying to send the following json to a REST server from JAVA

{

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


I am setting it as follows in my 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);


This gives me a 400, after I remove

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


this is a valid input , not sure whats going on. The json from curl works fine, only fails in java

Answer

Have you tried json.put("ignore_volumes", true);?

Placing the Boolean true instead of the String true.

Comments