view raw
Laurens Wolf Laurens Wolf - 10 months ago 57
JSON Question

posting JSon in Java Play 2.0

Ihave a question about json posting in java play app.

I made this json post:

HttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpPost request = new HttpPost(getBaseUrl()+"testing?username=testUser&password=testUser");
StringEntity params =new StringEntity("Id:25786,Type:OPEN,startDate:2016-06-26,settleDate:2016-06-29,lenders:[{Id:38569,amount:5000,pool:false}],borrowers:[{contactPersonId:38579,amount:5000,}],Name:Testname");
HttpResponse response = httpClient.execute(request);
assertEquals("Ok got some data", response.getStatusLine());
// handle response here...
}catch (Exception ex) {
// handle exception here
} finally {
httpClient.getConnectionManager().shutdown(); //Deprecated

but for some reason it keeps giving bad request back.
also i see a respons from te url that it gets a request, but all of it's value is empty
Can anyone see why its giving bad request

Thanks in advance
Greets Laurens


The string is not valid JSON. Also, onsider adding:

request.addHeader("content-type", "application/json");