2016-06-28 25 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

做到了。 謝謝:) –