Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 189: https://www.intelvision.cn/api/v2/detection/detect?
at java.net.URI.create(URI.java:859)
at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69)
at com.zeno.api.util.HttpsClient.get(HttpsClient.java:99)
at com.zeno.api.util.JsoupCrawler.getPictures(JsoupCrawler.java:75)
at com.zeno.api.util.JsoupCrawler.main(JsoupCrawler.java:27)
Caused by: java.net.URISyntaxException: Illegal character in query at index 189: https://www.intelvision.cn/api/v2/detect
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.checkChars(URI.java:3002)
at java.net.URI$Parser.parseHierarchical(URI.java:3092)
at java.net.URI$Parser.parse(URI.java:3034)
at java.net.URI.<init>(URI.java:595)
at java.net.URI.create(URI.java:857)
... 4 more
原因:地址中涉及了特殊字符,如‘|’‘&’等。所以不能直接用String代替URI来访问。必须采用%0xXX方式来替代特殊字符
解决方法:参考链接
URL url = new URL(strUrl);
URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null);
HttpClient client = new DefaultHttpClient();
HttpGet httpget = new HttpGet(uri);