请求Local主机时没有主机错误的途径,但是Curl请求成功
我正在尝试通过我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论