gpt4 book ai didi

java.net.URI - : Illegal character in fragment at index XXX - due to character "#"

转载 作者:行者123 更新时间:2023-12-02 06:21:50 24 4
gpt4 key购买 nike

源码如下:(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 specification

The fragment identifier component of a URI allows indirect
identification of a secondary resource by reference to a primary
resource and additional identifying information. [...] A fragmentidentifier component is indicated by the presence of a number sign("#") character and terminated by the end of the URI.

格式为

fragment    = *( pchar / "/" / "?" )

其中 pchar

pchar       = unreserved / pct-encoded / sub-delims / ":" / "@"

其中unreservedpct-encodedsub-delims

unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="

换句话说,在表示片段开始的第一个 # 之后,# 不是有效字符。它需要被编码。使用%23

关于java.net.URI - : Illegal character in fragment at index XXX - due to character "#",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20941947/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com