我试图在我的 Spring Boot 项目中使用 GET API,但出现上述错误。下面是 API 代码以及我访问此 API 的代码
@RequestMapping(value = "/apiUrl", method = RequestMethod.GET)
public void apiMethodName(@RequestParam("restrictProfileDate")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") LocalDateTime restrictProfileDate) {
HttpHeaders headers = new HttpHeaders();
LocalDate dateValue= LocalDate.now();
Map<String, Object> params = new HashMap<>();
params.put("restrictProfileDate", dateValue.atStartOfDay());
ResponseEntity<String> response = restTemplate.exchange(apiEndPoint, HttpMethod.GET, new HttpEntity<>(params, headers), String.class, params);
我不确定您的错误是什么,但如果您记录您的响应和标题,也许您可以看到更多详细信息。出于调试目的,您可以为您的
Errorhandler
设置 RestTemplate
,如下所示:
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
public void handleError(ClientHttpResponse response) throws IOException {
System.out.printf("Response Status: %s%n", response.getRawStatusCode());
System.out.printf("Response Headers: %n%s%n", response.getHeaders());
System.out.printf("Response Body: %n%s%n", new String(getResponseBody(response)));
super.handleError(response);
}
});
`