我正在使用 RestTemplate 调用 AutoTask API。但是我收到一条错误消息: 500 Internal Server Error: [{"errors":["Unexpected character met while parsing value: %. Path '', line 0, position 0."]}]
代码:
@GetMapping("/all-clients")
private String getAllClients() {
String COMPANIES_API_URL_Prefix = "https://webservices14.autotask.net/ATServicesRest/V1.0/Companies/query?search=";
String COMPANIES_API_URL_Suffix = "{\"filter\":[{\"op\":\"in\",\"field\":\"CompanyType\",\"value\":[1]}]}";
try {
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
headers.set("ApiIntegrationCode", "HUCXSL....."); //values partially hidden as it is sensitive information
headers.set("UserName", "fdfsf...."); //values partially hidden as it is sensitive information
headers.set("Secret", "yR*42......"); //values partially hidden as it is sensitive information
HttpEntity entity = new HttpEntity(headers);
RestTemplate restTemplate = new RestTemplate();
String url = COMPANIES_API_URL_Prefix+URLEncoder.encode(COMPANIES_API_URL_Suffix);
System.out.println(entity);
System.out.println(url);
ResponseEntity<Company[]> response = restTemplate.exchange(url, HttpMethod.GET, entity, Company[].class);
System.out.println("Result - status ("+ response.getStatusCode() + ") has body: " + response.hasBody());
}
catch (Exception exception) {
System.out.println("** Exception: "+ exception.getMessage());
}
return "all_clients";
}