本文介绍了RestTemplate uriVariables未展开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用spring RestTemplate.getForObject()来访问rest端点,但我的uri变量没有展开,并作为参数附加到url。这是我到目前为止所得到的:

I try to access a rest endpoint by using springs RestTemplate.getForObject() but my uri variables are not expanded, and attached as parameters to the url. This is what I got so far:

Map<String, String> uriParams = new HashMap<String, String>();
uriParams.put("method", "login");
uriParams.put("input_type", DATA_TYPE);
uriParams.put("response_type", DATA_TYPE);
uriParams.put("rest_data", rest_data.toString());
String responseString = template.getForObject(endpointUrl, String.class, uriParams);

endpointUrl变量的值是 http://127.0.0.1/ service / v4_1 / rest.php 而且它的确如此,但我希望 http://127.0.0.1/service/v4_1/rest.php?method=login& ; input_type ... 要调用。
任何提示都表示赞赏。

the value of the endpointUrl Variable is http://127.0.0.1/service/v4_1/rest.php and it's exactely what it's called but I'd expect http://127.0.0.1/service/v4_1/rest.php?method=login&input_type... to be called.Any hints are appreciated.

我正在使用Spring 3.1.4.RELEASE

I'm using Spring 3.1.4.RELEASE

问候。

推荐答案

它基本上替换变量,如 {foo} 按价值计算:

http://www.sample.com?foo={foo}

变为:

http://www.sample.com?foo=2

如果 foo 是2。

这篇关于RestTemplate uriVariables未展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:12