0

I'm getting an exception saying Java URI Syntax Exception "java.io.IOException: java.net.URISyntaxException: Invalid % sequence: %wl in query at index 88:" when i try to connect from my android application.

It seems to be throwing the exception where in the URL it says "%wl" and following is the URL. is there a work around for this.

http://192.168.111.111:9000/RB/db.svc/upd?LinkId=184617ED1F21&IPs=fe80::1a46:17ff:feed:1f21%wlan0,192.168.1.127,&MNo=0771111111&sPin=000&Status=0
1
  • URLEncoder.encode to encode url queryString Commented Jan 8, 2013 at 11:54

1 Answer 1

4

If you want to use % in your URL the first you need to do is to encode it.

So first you need to replace that % with %25 in your string ....1f21%wlan0... with .....1f21%25wlan0.... before connecting.

You can use the following code for encoding the URL in Java

String encodedUrl = java.net.URLEncoder.encode(<your_url>,"UTF-8"); 

Have a look at the below links for more information.

1.How to encode url in java

2.URL encoding character reference

UPDATE :

If you don't want to use URL encoder then you can try this out :

yourURL.replaceAll("%", "%25");

It is fine here to replace a single special character, but it would be a tedious task to do like this if you have many special characters that require proper URL encoding.

Sign up to request clarification or add additional context in comments.

5 Comments

so you mean first to replace and then to encode the url? and when I do it it gives me a malformed url exception
if your are encoding it with URLEncoder then no need to replace, it will be automatically replaced.
then there must be some problem with your actual url
Managed to work it out. I just replaced the "%" with "%25" manually and it worked. did not need to use the URLEncoder at all.
I replaced "%" with "%25", it worked fine. This is what i used , [myURL.replaceAll("%", "%25")]. Hope, it will be useful for someone. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.