【问题标题】:Prevent Feign from adding a trailing slash to the URL防止 Feign 在 URL 中添加斜杠
【发布时间】:2019-03-06 08:21:46
【问题描述】:

我正在尝试使用以下 Feign 客户端在 Spring Boot 应用程序中检索在线图像内容。

@FeignClient(name = "image")
public interface ImageClient {

    @RequestMapping(method = RequestMethod.GET)
    byte[] getContent(URI uri) throws WebException;

}

我遇到的问题是,当我使用诸如https://images.foo.com/1234567/5c5a7f14-d5d4-4a79-9c2e-78fed8b738c5.jpeg?foo=123 之类的 URL 调用 getContent 方法时,对https://images.foo.com/1234567/5c5a7f14-d5d4-4a79-9c2e-78fed8b738c5.jpeg/?foo=123 进行了 HTTP 调用,并且我从服务器收到错误消息。

有什么办法可以防止Feign在查询参数前加斜线?

【问题讨论】:

  • 请问您找到解决方案了吗?我也面临同样的问题。

标签: spring-cloud-feign feign


【解决方案1】:

为了避免这种情况 分割网址

@FeignClient(name = "image" ,value url = "BASE")
public interface ImageClient {

    @RequestMapping(method = RequestMethod.GET ,value  = "X" )
    byte[] getContent(URI uri) throws WebException;

}

final 是 B/X 没有尾随/添加

【讨论】:

    【解决方案2】:

    你也可以

    @FeignClient(name = "image" ,  url = "BASE") 
    public interface ImageClient {
    
    @RequestMapping(method = RequestMethod.GET   )
    byte[] getContent(URI uri) throws WebException;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2021-04-18
      • 1970-01-01
      • 1970-01-01
      • 2021-08-24
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      相关资源
      最近更新 更多