我的代码
url = "https://www.payumoney.com/payment/payment/addPaymentSplit?merchantKey=test&merchantTransactionId=test&totalAmount=0&totalDiscount=0&jsonSplits=[{"amountToBeSettled":0,"aggregatorDiscount":0,"splitDetails":"test","CODAmount":0,"splitAmount":0,"merchantId":"0000","aggregatorCharges":0,"CODMode":0,"aggregatorSubTransactionId":"test","sellerDiscount":0}]"
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
我在第二行收到非法字符错误。我尝试编码[到%5B和]到%5D。仍然是同样的错误。
使用apache-commons-httpclient库。
答案 0 :(得分:0)
不要重新发明轮子,使用内置的https://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html:
"...&jsonSplits=" + URLEncoder.encode("[{...", "UTF-8");
它为您翻译保留字符。