Spring Boot 中的编码/解码

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

我有一个 Spring Boot 应用程序 (A1),我需要通过 Rest API 调用另一个应用程序 (A2)。 A1是用Java + Spring Boot编写的,而A2是用python和tornado编写的。 A1 正在尝试调用 A2 公开的 /Get。 /Get url 类似于:

https:123.456:123/something?industry=Test Data O&G Upstream - NA & Europe
。 A1 应用程序将上述 requestParam 编码为
industry=Test+Data+O%26G+Upstream+-+NA+%26+Europe
。根据我到目前为止的分析,导致问题的是
&

我正在使用

URLEncoder
对值进行编码。

同样的请求适用于邮递员,但不适用于 Spring Boot。

python java spring-boot microservices tornado
1个回答
0
投票

同意@Wonka。 Postman 识别特殊字符并将 & 立即编码为 %26。当请求发送时,邮递员会像正常参数编码一样再次编码 %26。

因此,要实现相同的行为,您需要将 &“Test Data O&G Upstream - NA & Europe”替换为 %26 ->“Test Data O%26G Upstream - NA %26 Europe”,然后将其传递给 URLEncoder。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.