简体   繁体   English

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

[英]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. 当我尝试从Android应用程序进行连接时,出现exceptionJava URI Syntax Exception "java.io.IOException: java.net.URISyntaxException: Invalid % sequence: %wl in query at index 88:"

It seems to be throwing the exception where in the URL it says "%wl" and following is the URL. 似乎引发了exception ,其中URL中显示"%wl" ,然后是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. 如果要在URL中使用% ,则首先需要对其进行编码。

So first you need to replace that % with %25 in your string ....1f21%wlan0... with .....1f21%25wlan0.... before connecting. 所以,首先你需要更换%%25在你的字符串....1f21%wlan0........1f21%25wlan0....连接之前。

You can use the following code for encoding the URL in Java 您可以使用以下代码对Java中的URL进行编码

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 1.如何在Java中编码url

2.URL encoding character reference 2.URL编码字符参考

UPDATE : 更新:

If you don't want to use URL encoder then you can try this out : 如果您不想使用URL编码器,则可以尝试以下方法:

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. 在这里替换单个特殊字符是可以的,但是如果您有许多需要正确URL编码的特殊字符,这样做就很繁琐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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