我尝试使用 springs RestTemplate.getForObject() 访问休息端点,但我的 uri 变量没有展开,并作为参数附加到 url。这是我到目前为止得到的:
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...
被调用。
任何提示表示赞赏。
我正在使用 Spring 3.1.4.RELEASE
问候。
最佳答案
RestTemplate
中没有追加一些查询字符串逻辑它基本上用它们的值替换像 {foo}
这样的变量:
http://www.sample.com?foo={foo}
变成:
http://www.sample.com?foo=2
如果 foo
为 2。
关于java - RestTemplate uriVariables 未展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20705377/