在 Java Play 2.0 中发布 JSon
posting JSon in Java Play 2.0
我有一个关于 json post 在 java 播放应用中的问题。
我做了这个 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
}
但出于某种原因,它一直在返回错误的请求。
我还看到来自 te url 的回复说它收到了一个请求,但它的所有值都是空的
任何人都可以看到为什么它给出错误的请求
提前致谢
问候劳伦斯
字符串无效 JSON。另外,考虑添加:
request.addHeader("content-type", "application/json");
我有一个关于 json post 在 java 播放应用中的问题。
我做了这个 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
}
但出于某种原因,它一直在返回错误的请求。 我还看到来自 te url 的回复说它收到了一个请求,但它的所有值都是空的 任何人都可以看到为什么它给出错误的请求
提前致谢 问候劳伦斯
字符串无效 JSON。另外,考虑添加:
request.addHeader("content-type", "application/json");