首页 > 解决方案 > 如何在 URL 中使用 ^ 读取查询参数

问题描述

我正在尝试为 eBay 实现回调端点。eBay 调用此端点以将用户令牌交给应用程序。

我可以按预期定义我的端点

http://localhost:8080/api/ebay/auth

这里没有什么不寻常的。我的观点看起来像这样,非常基本:

@RestController
@RequestMapping(path = ["/api/ebay/auth"])
class EbayAuthController {

    @GetMapping(path = [""])
    fun getAccessToken(@RequestParam code: String) {
        println("Auth code: $code")
    }

}

现在 eBay 将参数code与值一起传递

?code=v^1.1%23i^1%23r^1%23p^3%23I^3%23f^0%23t^[excluded_user_token]&expires_in=299

当我用这个数据集调用我的端点时,它返回400 Bad Request. 我可以通过添加^到任何请求来重现这一点。我读到这是一个不安全的字符使用 - 但问题是:Ebay 使用这个字符返回用户令牌,所以我必须阅读它。

当我传递一个样本时,http://localhost:8080/api/ebay/auth?code=123它会按预期打印代码。

我从来没有遇到过这个问题,任何人都可以帮助我或指出正确的方向如何解决这个问题?

标签: spring

解决方案


根据Dirk DeyneSpring-boot controller error when url contains brackets character 问题的回答,您可以在以下内容中指定:server.tomcat.relaxed-query-charsapplication.properties

server.tomcat.relaxed-query-chars=^

推荐阅读