• Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 189......


    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);
    很多事情不是看到希望才去坚持,而是坚持了才会看到希望
  • 相关阅读:
    无参装饰器
    针对硬盘大于2TB,centos7系统安装问题说明
    Java与Python擅长领域
    Java数据类型
    编译型语言与解释型语言,强类型语言与弱类型语言,动态类型语言与静态类型语言
    Butterfly透明背景设置
    虚拟机重装系统
    手动删除软件垃圾
    清理C盘
    Gitee+HEXO搭建个人博客
  • 原文地址:https://www.cnblogs.com/isisbenben/p/6293364.html
Copyright © 2020-2023  润新知