首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Feign - URL编码路径参数

Feign - URL编码路径参数
EN

Stack Overflow用户
提问于 2017-05-10 17:57:47
回答 2查看 11.1K关注 0票数 6

这是我的合同

代码语言:javascript
复制
@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

有什么办法可以解决这个问题吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-05-11 00:49:22

一个简单的配置就做到了,

代码语言:javascript
复制
@RequestLine(value = "GET /products/{id}", decodeSlash = false)
@Headers({"Content-Type: application/json"})
ApiResponse getProduct(@Param("id") String productId) throws Exception;

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

票数 4
EN

Stack Overflow用户

发布于 2021-05-11 19:31:09

在我的例子中,当代码看起来像这样时:

代码语言:javascript
复制
@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有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43889140

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档