Laurens Wolf
Laurens Wolf

Reputation: 39

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");
        request.setEntity(params);
        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

Upvotes: 0

Views: 28

Answers (1)

seairth
seairth

Reputation: 2062

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

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

Upvotes: 1

Related Questions