【发布时间】:2019-08-28 09:16:09
【问题描述】:
我的 Spring Boot 应用程序中的 Api Call 遇到了一个奇怪的问题。当我使用 restTemplate 调用 API 时:
ResponseEntity<String> response;
HttpHeaders headers = new HttpHeaders();
headers.set("X-Api-Key", "blablabla");
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity entity = new HttpEntity(headers);
try {
response = restTemplate.exchange(uri, HttpMethod.GET, entity, String.class);
} catch (HttpClientErrorException e) {
throw new HttpClientErrorException(e.getStatusCode());
}
我无法得到被调用 API 的任何响应。它总是返回 200 Http 状态,但正文如下:
<200 OK,<html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 6140245264157490471</body></html>,{Connection=[close], Cache-Control=[no-cache], Content-Type=[text/html; charset=utf-8], Pragma=[no-cache], Content-Length=[188]}>
我尝试在 Postman 中使用我的应用程序中使用的 uri 和标头调用 API,它可以正常工作:/
我已经在 SOF 和 Google 中搜索过类似的问题,但找不到任何响应。
我希望有人能帮助我:D
谢谢
【问题讨论】:
-
是否设置了
Content-Type标头? -
@AlirezaKhajavi 这是一个 GET 请求,所以我不需要
Content-Type标头,不是吗? -
请检查它以将
Content-Type设置为application/json,并请告诉我发生了什么。 -
我试过了,它返回了同样的信息
-
该错误消息似乎来自 F5 网络设备:stackoverflow.com/a/28353068/657224