如何将网址作为休息服务传递?

时间:2015-07-06 10:24:52

标签: spring rest spring-mvc spring-boot

我正在尝试在spring boot中构建一个rest服务来更新我的数据库..

 @RequestMapping(value = "/setrepacking/{transaction_number}/{image_url}", method = RequestMethod.GET)
   public String setRepackingDetails(@PathVariable String transaction_number,
                                     @PathVariable  String image_url) {

    dao.setRepackingDetails(transaction_number, image_url);
    return "Updated repacking details for "+transaction_number;
   }

但我的image_url如下所示:我想在下面作为休息组件的一部分传递

  

http://xxxx.com/api/images/get?format=src&type=png

我正在尝试以下内容:

`www.localhost:8080/setrepacking/3500574684/http://thecatapi.com/api/images`/get?format=src&type=png

它不接受......

如何在我的broswer中传递参数?
应用任何快速解决方案......

1 个答案:

答案 0 :(得分:1)

您必须对图片网址路径变量进行URL编码,然后才能将其传递给请求,编码后的网址如下所示:

http%3A%2F%2Fxxxx.com%2Fapi%2Fimages%2Fget%3Fformat%3Dsrc%26type%3Dpng

所以你要求必须看起来像这样:

http://localhost:8080/setrepacking/3500574684/http%3A%2F%2Fxxxx.com%2Fapi%2Fimages%2Fget%3Fformat%3Dsrc%26type%3Dpng

这样您就可以正确获取图片网址。另请查看URLEncoderURLDecoder

相关问题