【问题标题】:RestTemplate Exchange return Url RejectedRestTemplate 交换返回 URL 被拒绝
【发布时间】: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

标签: spring-boot resttemplate


【解决方案1】:

我找到了问题的解决方案。这似乎是公司防火墙的一个错误,将这个电话视为威胁;)

【讨论】:

    猜你喜欢
    • 2012-06-18
    • 1970-01-01
    • 2017-08-09
    • 2017-06-01
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多