2013-04-15 32 views
0

我有一个JSON字符串是:通过调用HttpClient的使用JSON参数的方法不能正常工作

`{ 
    "portfolio": "HEXGENFUND", 
    "transSrlNo": "1", 
    "transCode": "BUY", 
    "investReason": "004", 
    "inflowOutflow": "I", 
    "transDate": "2012-09-01", 
    "tradeDate": "2012-09-01", 
    "tradeDateUpto": "2012-09-01", 
    "tradeTime": "11:27:9", 
    "investCategory": "FVTPL", 
    "custodian": "DEUTSCHE", 
    "holdType": "HOLD", 
    "securityType": "INV", 
    "security": "DABU02", 
    "assetClass": "EQU", 
    "issuer": "DABU", 
    "marketType": "MKT", 
    "tradePriceType": "S", 
    "requisitionType": "SO", 
    "priceFrom": "100000", 
    "priceTo": "100000", 
    "marketPrice": "100000", 
    "averagePrice": "100000", 
    "price": "100000", 
    "quantity": "2", 
    "grossAmtTcy": "200000", 
    "exchRate": "1", 
    "grossAmtPcy": 200000, 
    "grossIntTcy": "0", 
    "grossIntPcy": 0, 
    "netAmountTcy": 200000, 
    "netAmountPcy": 200000, 
    "acquCostTcy": 200000, 
    "acquCostPcy": 200000, 
    "yieldType": "N", 
    "purchaseYield": "0", 
    "marketYield": "0", 
    "ytm": "0", 
    "mduration": "0", 
    "currPerNav": "0", 
    "desiredPerNav": "0", 
    "currHolding": "0", 
    "noofDays": "0", 
    "realGlPcy": 0, 
    "realGlTcy": "0", 
    "nowLater": "N", 
    "isAllocable": "false", 
    "acquCostReval": 0, 
    "acquCostHisTcy": 200000, 
    "acquCostHisPcy": 0, 
    "exIntTcy": 0, 
    "exIntPcy": 0, 
    "accrIntReval": 0, 
    "accrIntTcy": 0, 
    "accrIntPcy": 0, 
    "grossAodTcy": 0, 
    "grossAodPcy": 0, 
    "grossAodReval": 0, 
    "bankAccAmtAcy": 200000, 
    "bankAccAmtPcy": 200000, 
    "taxAmountTcy": 0, 
    "unrelAmortTcy": 0, 
    "unrelAmortPcy": 0, 
    "unrelGlTcy": 0, 
    "unrelGlPcy": 0, 
    "realGlHisTcy": 0, 
    "realGlHisPcy": 0, 
    "tradeFeesTcy": 0, 
    "tradeFeesPcy": 0 
}` 

我尝试调用它接受上述参数通过HttpClient的方法。当我打电话像下面的方法:

uri = "http://localhost:8080/api/trade/createrequisition"; 
HttpPost postURI = new HttpPost(uri); 
      postURI.setHeader("Content-type", "application/json"); 
      // Setup the request parameters 
      BasicHttpParams params = new BasicHttpParams(); 
      params.setParameter("CreateRequisitionRO", jsonROConverter.serialiseRequisionRO(request)); 
      params.setBooleanParameter("validateOnly", validateOnly); 
      postURI.setParams(params); 

      HttpResponse responseURL = client.execute(postURI); 

这是什么方法调用签名:

public @ResponseBody 
    void createRequisition(@RequestBody CreateRequisitionRO[] request, 
      @RequestHeader("validateOnly") boolean validateOnly) {....} 

这个例外,我得到:

java.io.EOFException: No content to map to Object due to end of input 

可能是什么问题。

请帮我解决这个问题。

回答

-1
StringRequestEntity requestEntity = new StringRequestEntity(
    JSON_STRING, 
    "application/json", 
    "UTF-8"); 

PostMethod postMethod = new PostMethod("http://localhost:8080/api/trade/createrequisition"); 
postMethod.setRequestEntity(requestEntity); 

int statusCode = httpClient.executeMethod(postMethod); 
+0

感谢我的帖子我的方法executeMethod(PostMethod)是未定义的类型HttpClient'。我使用HttpClient 4.0版本 –

相关问题