gpt4 book ai didi

java - Spring Cloud Contract - 如何在 .yaml 文件中传递 "+"(加号)作为查询参数

转载 作者:太空宇宙 更新时间:2023-11-04 09:40:01 24 4
gpt4 key购买 nike

当我尝试以不同方式传递“+”号作为查询参数的一部分时,它会对任何结果进行编码。

我希望传递带有 +380999418260 值的 phone 参数。

尝试了最期望的正确方法:

request:
method: GET
url: /customers/prepaid
queryParameters:
phone: "%2B380999418260"
headers:
Content-Type: application/x-www-form-urlencoded

还尝试直接从 url 传递:

request:
method: GET
url: /customers/prepaid?phone=%2B380999418260
headers:
Content-Type: application/x-www-form-urlencoded

两者都说手机是%2B380999418260

从日志中,它转换%符号:

"X-Query-String":"phone=%252B380999418260"

我还尝试以非编码方式传递它:

request:
method: GET
url: /customers/prepaid
queryParameters:
phone: "+380999418260"
headers:
Content-Type: application/x-www-form-urlencoded

但在本例中,它将 + 号转换为空格字符。

当我使用此 uri /customers/prepaid?phone=%2B380999418260 从 Postman 访问此端点时,它会返回正确的响应,其中使用带有“+”号的正确电话。

最佳答案

根据this question ,你不能直接传递 + 符号,它应该被编码。但在服务器端,您可以使用 URLDecoder 解码接收到的字符串。类:

String myString = "%2B380999418260";
URLDecoder.decode(myString, "ISO-8859-1");
// output: +380999418260

关于java - Spring Cloud Contract - 如何在 .yaml 文件中传递 "+"(加号)作为查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56090110/

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