请求Local主机时没有主机错误的途径,但是Curl请求成功

发布于 2025-02-01 04:41:12 字数 2197 浏览 3 评论 0原文

我正在尝试通过我的Java代码从一项服务到另一个服务的POST请求。这两种服务始终在同一服务器上运行 我正在为此使用RESTTEMPLATE。请求URL:

    RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
    HttpHeaders headers = new HttpHeaders();
    headers.set(HttpHeaders.CONTENT_TYPE, "application/x-protobuf");
    headers.set(HttpHeaders.ACCEPT, "text/plain");
    org.springframework.http.HttpEntity<byte[]> request = new org.springframework.http.HttpEntity<>(definitions.toByteArray(), headers);
    String url =  "http://localhost:8888/product-details/api/1.0/external_launches";
    restTemplate.exchange(url, HttpMethod.POST, request, Void.class);

当我在我的Linux服务器之一上运行此代码时,这是我遇到的错误:

2022-05-06 08:42:32,979 [209: Normal Priority Request Pool-62] ERROR test_appliance - I/O error on POST request for "http://localhost:8888/product-details/api/1.0/external_launches": No route to host (Host unreachable); nested exception is java.net.NoRouteToHostException: No route to host (Host unreachable):org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8888/product-details/api/1.0/external_launches": No route to host (Host unreachable); nested exception is java.net.NoRouteToHostException: No route to host (Host unreachable)
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8888/product-details/api/1.0/external_launches": No route to host (Host unreachable); nested exception is java.net.NoRouteToHostException: No route to host (Host unreachable)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:675) ~[spring-web-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:622) ~[spring-web-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:540) ~[spring-web-4.3.25.RELEASE.jar:4.3.25.RELEASE]

但是当我进入Linux框中并做出这样的卷曲请求时,

curl -X POST http://localhost:8888/product-details/api/1.0/external_launches

遇到的主要问题是行为仅在我的1台Linux机器中可再现。我还有其他3台Linux机器,Java代码可以很好地工作。

有什么想法吗?

I am trying to make a POST request from one service to another service from my Java code. Both of the services are always running on the same server
I am using restTemplate for this. Request URL :

    RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
    HttpHeaders headers = new HttpHeaders();
    headers.set(HttpHeaders.CONTENT_TYPE, "application/x-protobuf");
    headers.set(HttpHeaders.ACCEPT, "text/plain");
    org.springframework.http.HttpEntity<byte[]> request = new org.springframework.http.HttpEntity<>(definitions.toByteArray(), headers);
    String url =  "http://localhost:8888/product-details/api/1.0/external_launches";
    restTemplate.exchange(url, HttpMethod.POST, request, Void.class);

When I ran this code on one of my linux servers, this is the error I got :

2022-05-06 08:42:32,979 [209: Normal Priority Request Pool-62] ERROR test_appliance - I/O error on POST request for "http://localhost:8888/product-details/api/1.0/external_launches": No route to host (Host unreachable); nested exception is java.net.NoRouteToHostException: No route to host (Host unreachable):org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8888/product-details/api/1.0/external_launches": No route to host (Host unreachable); nested exception is java.net.NoRouteToHostException: No route to host (Host unreachable)
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:8888/product-details/api/1.0/external_launches": No route to host (Host unreachable); nested exception is java.net.NoRouteToHostException: No route to host (Host unreachable)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:675) ~[spring-web-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:622) ~[spring-web-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:540) ~[spring-web-4.3.25.RELEASE.jar:4.3.25.RELEASE]

But when I ssh into the linux box and make a curl request like this

curl -X POST http://localhost:8888/product-details/api/1.0/external_launches

It works fine

The main problem I have is that this kind of behaviour is only reproducible in 1 of my linux machines. I have 3 other linux machines on which the Java code works perfectly fine.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文