gpt4 book ai didi

api - AWS API Gateway 获取带有 '+' 符号的请求查询参数不起作用

转载 作者:行者123 更新时间:2023-12-02 20:49:48 25 4
gpt4 key购买 nike

我已经在 API 网关中实现了 GET 请求,并且工作正常,但今天我得到一个名称,其中有“+”符号,所以有人知道 .../score?team=name+with +sign 不起作用,因为 ..../score?team-with-dashes 工作得很好。请求的内容类型为application/json。

这是 body 映射模板(application/json)

{
"body" : $input.json('$'),
"headers": {
#foreach($header in $input.params().header.keySet())
"$header": "$util.escapeJavaScript($input.params().header.get($header))" #if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"params": {
#foreach($param in $input.params().path.keySet())
"$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end
#end
},
"query": {
#foreach($queryParam in $input.params().querystring.keySet())
"$queryParam": "$util.escapeJavaScript($input.params().querystring.get($queryParam))" #if($foreach.hasNext),#end
#end
}
}

这与 URL 查询字符串参数还是其他相关?

最佳答案

查询参数中的+字符是一个特殊字符。它是空格 字符的替换字符。

因此,如果客户端打算发送带有空格的 .../score?team=name,则客户端可以将 URL 编码为 .../score?team=name+与+空格。它还可以将其编码为 .../score?team=name%20with%20spaces

这意味着在服务器端,参数应该未编码,并将 + 转换回空格。

如果您确实希望查询参数值中包含 + 字符,则必须将其编码为 %2B,例如 .../score? team=name%2Bwith%2Bsign

关于api - AWS API Gateway 获取带有 '+' 符号的请求查询参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42629856/

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