0

Please help me to figure out my question answer i tried to find so many times on Google but i cant able to find its solution.

First i am getting this exception

 java.lang.IllegalArgumentException: Illegal character in query at index 130

than after i add this code in my code.

String restUrl = URLEncoder.encode(url, "UTF-8");
HttpGet httpget = new HttpGet(restUrl);

then i am getting this exception

java.lang.IllegalStateException: Target host must not be null, or set in parameters.

Please help me solve out from this exception. Please.

Here is my code.

sam_k
  • 5,983
  • 14
  • 76
  • 110

1 Answers1

0

Android: howto parse URL String with spaces to URI object?

You should in fact URLEncode the "invalid" characters. Since the string actually contains the complete URL, it's hard to properly URL-encode it. You don't know which slashes / should be taken into account and which not. You cannot predict that on a raw String beforehand. The problem really needs to be solved at a higher level. Where does that String come from? Is it hardcoded? Then just change it yourself accordingly. Does it come in as user input? Validate it and show error, let the user solve itself.

Community
  • 1
  • 1
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36