2016-06-28 26 views
0

我有一个关于json在java play app中发布的问题。
我发这个帖子的JSON:在Java中发布JSon Play 2.0

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 
    } 

,但由于某种原因,它一直给错误的请求回。 还我看到TE URL,它得到的请求的respons,但它的所有值为空 有人能看到为什么它给人错误的请求

在此先感谢 电贺劳伦斯

回答

1

的字符串无效JSON。另外,旁加:

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

做到了。 谢谢:) –