这是我的合同
@RequestLine("GET /products/{id}")
@Headers({"Content-Type: application/json"})
ApiResponse getProduct(@Param("id") String productId) throws Exception;我想获取id = "a/b“的产品,
如果我将此作为参数发送给getProduct("a/b")
然后,形成的URL是http://api/products/a/b,而我得到的是404,而url应该是http://api/products/a%2Fb。
有什么办法可以解决这个问题吗?
发布于 2017-05-11 00:49:22
一个简单的配置就做到了,
@RequestLine(value = "GET /products/{id}", decodeSlash = false)
@Headers({"Content-Type: application/json"})
ApiResponse getProduct(@Param("id") String productId) throws Exception;路径参数的编码是正确的,但是在发出导致问题的请求之前,RequestTemplate再次解码了URL (默认情况下是decodeSlash=true)。
发布于 2021-05-11 19:31:09
在我的例子中,当代码看起来像这样时:
@GetMapping(path = "/document/{documentId}/files/{fileId}")
ResponseEntity<byte[]> getDocument(@PathVariable("documentId") String documentId, @PathVariable(value = "fileId") String fileId);另一个问题是@PathVariable fileId可能是123/SGINED。
设置application.property feign.client.decodeSlash=false有帮助。
https://stackoverflow.com/questions/43889140
复制相似问题