How to deal with the URISyntaxException

后端 未结 10 2077
攒了一身酷
攒了一身酷 2020-11-28 09:22

I got this error message :

java.net.URISyntaxException: Illegal character in query at index 31: http://finance.yahoo.com/q/h?s=^IXIC

10条回答
  •  我在风中等你
    2020-11-28 09:32

    A space is encoded to %20 in URLs, and to + in forms submitted data (content type application/x-www-form-urlencoded). You need the former.

    Using Guava:

    dependencies {
         compile 'com.google.guava:guava:28.1-jre'
    }
    

    You can use UrlEscapers:

    String encodedString = UrlEscapers.urlFragmentEscaper().escape(inputString);
    

    Don't use String.replace, this would only encode the space. Use a library instead.

提交回复
热议问题