简体   繁体   中英

Android java.io.IOException: java.net.URISyntaxException:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM