Java URLDecode 失败,而 PHP urldecode 部分解码



这是一个格式错误的URL http%3A%2F%2Fexample.com%2

使用PHP的

var_dump(urldecode("http%3A%2F%2Fexample.com%2")); 

我得到

string(20) "http://example.com%2"

但是,当使用Java时

URLDecoder.decode("http%3A%2F%2Fexample.com%2", StandardCharsets.UTF_8.toString()); 

我得到

java.lang.IllegalArgumentException: URLDecoder: Incomplete trailing escape (%) pattern

这是一个简化的 URL,用于展示我的示例。我怎样才能在 Java 中尽可能多地解析 URL,即使它的格式不正确?基本上,返回 PHP 返回的内容。

什么是自然网址?我的意思是,最后,有 2%,http%3A%2F%2Fexample.com%2 的自然含义是什么?是 http://example.com/吗?似乎最后剥离了一个角色。

最新更新