Feign - URL 编码路径参数

Nit*_*nde 6 spring-boot netflix-feign feign

这是我的契约

@RequestLine("GET /products/{id}")
@Headers({"Content-Type: application/json"})
ApiResponse getProduct(@Param("id") String productId) throws Exception;
Run Code Online (Sandbox Code Playgroud)

我想获取 id = "a/b" 的产品,

如果我将此作为参数发送给 getProduct("a/b")

然后形成的 URL 是http://api/products/a/b404,而不是 URL 应该是http://api/products/a%2Fb

有没有解决的办法?

Nit*_*nde 7

一个简单的配置就完成了,

@RequestLine(value = "GET /products/{id}", decodeSlash = false)
@Headers({"Content-Type: application/json"})
ApiResponse getProduct(@Param("id") String productId) throws Exception;
Run Code Online (Sandbox Code Playgroud)

路径参数已正确编码,但 RequestTemplate 在发送导致问题的请求之前再次解码 URL(默认情况下decodeSlash=true)。