Java 将 URL 空间转换为“%20”而不是 +

问题描述 投票:0回答:0

我正在对字符串进行 URL 编码。当前代码将空格变成 "+" 而不是 "%20" 。我怎样才能更改代码来执行此操作?

代码:

httpURLEncoded = URLEncoder.encode(httpUrl, StandardCharsets.UTF_8.toString());
HttpGet getRequest = new HttpGet(httpURLEncoded);
getRequest.setHeader("Content-type", "application/json");

Goal: ABC%20XYZ instead of ABC+XYZ

我认为 UTF 8 是正确的,它应该有所不同吗?

资源:

https://www.w3schools.com/tags/ref_urlencode.ASP

Java URL 参数用空格替换 %20

java apache urlencode
© www.soinside.com 2019 - 2024. All rights reserved.