-1

My code

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);

I am getting illegal character error on the second line. I tried encoding [ to %5B and ] to %5D. Still the same error.

using apache-commons-httpclient library.

nyi
  • 3,123
  • 4
  • 22
  • 45
  • This question is duplicate It is already answered https://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters – Dhruv Raj Singh Apr 23 '18 at 09:21

1 Answers1

0

Don't reinvent the wheel, use the built-in https://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html:

"...&jsonSplits=" + URLEncoder.encode("[{...", "UTF-8");

It translates the reserved characters for you.

ewramner
  • 5,810
  • 2
  • 17
  • 33