[英]java.net.URI - : Illegal character in fragment at index XXX - due to character “#”
源代碼如下:(a-zA-Z全部替換為x)
String url = "xxxxx://xx730xxxxxxx005.xxxx.xxx:8443/xxx/xxxxxxxxx.xxxx#xxxxxx=xxxxxxx2&&xxxxxxxxx=1388782204000&&xxxxxxx=1388785804000&&xxxxx=xxxxxxxxxxx='xxx-xx730xxxxx10'%20xxx%20xxxxxxxx='__xxx__xxx_xxx_xxxxxxx_xxxx_xxxxxxxxx_#2_xxx-xx__xxx_xxx_xxxxxxx_______xxxx'"
System.out.println(url2.charAt(215)); -> result #
URI.create(url2); // illegal character exception
我不明白為什么當它是一個有效的URL字符時,我會在索引215處獲得“#”中的非法字符。
URI規范說明
URI的片段標識符組件允許間接
通過引用主要來識別輔助資源
資源和其他識別信息。 [...] 片段標識符組件由數字符號(“#”)字符的存在表示,並由URI的末尾終止。
格式是
fragment = *( pchar / "/" / "?" )
pchar
在哪里
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
其中unreserved
, pct-encoded
和sub-delims
是
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
換句話說, #
在第一個#
之后不是有效字符,表示片段的開頭。 它需要編碼。 使用%23
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.