I am trying to parse the following URI:
but found this error message: / P>
java.net.URISyntaxException: Invalid character in index 34: http: //translate.google.com/#zh-CN | En | You at java.net.URI $ parser.phile (URI Java 80809) $ Parser.checkChars at java.net.URI (URI.java, 982) java.net.URI $ Parser.parse (URI.java:3028 )
"|" The problem with the character, if I "|" If you get rid of, then the Chinese axis is not causing any problem, what is the right way to handle it?
My method looks like this:
Browse (new URI (file_or_rl ("", "% 20"). Substitution ("^", "% 5E") )); } Hold (exception e) {e.printStackTrace (); Thanks for the reply}, but the solution of BalusC seems to work only for an example URL, my method requires that I have to work with any url near it, how will it know where the URL is divided into two parts Only the starting point and the second part to cut into the encoding?
The character of the pipe is to use it in the URL, you can fix it by changing it. With its encoded hex counterpart, which will be "% 7C"
However, changing the individual characters in the URL is a brittle solution that does not work very well when you believe that someone In the given URL, there might be a number of potentially many different characters that may have to be replaced. You are already replacing spaces, carats and pipes .... But what about brackets, and accent marks and quotes? Or question mark and ampersand, which can not be based on legitimate parts of the URL or not, how is it used?
Thus, a better solution would be to use the language feature for the encoding of the URL, in case of Java it is in the case of Java, in the example of BalusC in the example of this question Use accordingly.
No comments:
Post a Comment