[英]httpclienterror during get request for resttemplate
I keep getting the below exception when I try to do a GET
request.当我尝试执行
GET
请求时,我不断收到以下异常。 A direct curl request to the url works fine but this doesn't.对 url 的直接 curl 请求可以正常工作,但事实并非如此。 I'm trying to call service on port
8085
from the service on port 8082
.我正在尝试从端口
8082
上的服务调用端口8085
上的服务。
Code代码
ResponseEntity<List<String>> quoteResponse = restTemplate.exchange("http://localhost:8085/rest/test/{username}", HttpMethod.GET,
null, new ParameterizedTypeReference<List<String>>() {
},userName);
Curl Curl
curl 'http://localhost:8082/rest/test/user1' -H "Content-Type: application/json"
Error错误
org.springframework.web.client.HttpClientErrorException$NotFound: 404 : [<Map><timestamp>2020-06-18T23:35:31.449+00:00</timestamp><status>404</status><error>Not Found</error><message></message><path>/rest/test/user1</path></Map>]
at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:113) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:184) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:125) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
where is your request header "Content-Type: application/json"您的请求在哪里 header "Content-Type: application/json"
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<JSONObject> req = new HttpEntity<>(new HashMap(), httpHeaders);
ResponseEntity<List<String>> quoteResponse = restTemplate.exchange("http://localhost:8085/rest/test/{username}", HttpMethod.GET,
req, new ParameterizedTypeReference<List<String>>() {
},userName);
The issue seems to be with the ports 8081
worked fine.问题似乎在于端口
8081
工作正常。 So there seems to be some connectivity issue between 8082
and 8085
.所以
8082
和8085
之间似乎存在一些连接问题。 Very Strange for me.对我来说很奇怪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.