How to deal with the URISyntaxException

后端 未结 10 2082
攒了一身酷
攒了一身酷 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:38

    A general solution requires parsing the URL into a RFC 2396 compliant URI (note that this is an old version of the URI standard, which java.net.URI uses).

    I have written a Java URL parsing library that makes this possible: galimatias. With this library, you can achieve your desired behaviour with this code:

    String urlString = //...
    URLParsingSettings settings = URLParsingSettings.create()
      .withStandard(URLParsingSettings.Standard.RFC_2396);
    URL url = URL.parse(settings, urlString);
    

    Note that galimatias is in a very early stage and some features are experimental, but it is already quite solid for this use case.

提交回复
热议问题