0

I am getting this error when I use HttpClient. I have looked at many answers from SO but none seem to answer mine. Here in the URL I have URLEncoded only the message. I can't for the world figure out the illegal character. The other answers have a special character like "{" or "|" in the URL. There are none in mine. Yet I get the exception. I am at my wits end.

Here is the Stack trace:

java.lang.IllegalArgumentException: Illegal character in query at index 95:     http://api.alerts.sinfini.com/v3/index.php?method=sms&api_key=XXXXXXXX&to=1234567890&sender=SIDEMO&message=Oyeseva+Registration+Verification+Code%3A+366509&format=json&custom=1,2&flash=0
    at java.net.URI.create(URI.java:859)
    at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69)
    at com.oyeseva.messaging.SMSSender.sendSMS(SMSSender.java:58)
    at com.oyeseva.messaging.SMSSender.send(SMSSender.java:104)
    at com.oyeseva.messaging.alerts.SendMesssageOrEmail.alertIsAnSMS(SendMesssageOrEmail.java:71)
    at com.oyeseva.messaging.alerts.SendMesssageOrEmail.run(SendMesssageOrEmail.java:42)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Edit: I have used URLEncoder to encode the whole URL but it chokes on errors. Also tried encoding the query only..says the method is missing...the method is sms here in the URL.

Mallik Kumar
  • 540
  • 1
  • 5
  • 28

2 Answers2

0

looks to me like this is try to parse the API key to a value suitable for the type that api_key uses, but is not able to parse XXXX into that type.

0

try URLEncoder class first to encode your url. then put that url into HTTPClient class.

String safeUrl = URLEncoder.encode("stringurl", "UTF-8");

How URLEncoder Encodes the URL

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52