我正在尝试使用(GET)休息服务。
http://localhost:7010/abc/status?configFilePath=config%2Fconfig.properties
我正在尝试使用Spring RestTemplate服务
以下是我用于restTemplate的代码:
String configFile = "config/config.properties";
Map<String,String> restvars = new HashMap<String,String>();
restvars.put("configFilePath", configFile);
RestTemplate restTemplate = new RestTemplate();
String restUrl = http://localhost:7010/abc/status?
String restCall = restTemplate.getForObject(restUrl, String.class, restvars);
System.out.println(restCall.toString());
它抛出
Required String parameter 'configFilePath' is not present
Map是否实际传递参数?
答案 0 :(得分:0)
我从错误的角度看着它。这个SO问题的答案有所帮助。
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
.queryParam("configFilePath", configFile);
HttpEntity<?> entity = new HttpEntity<>(headers);
HttpEntity<String> response = restTemplate.exchange(builder.toUriString(),String.class);