【发布时间】:2023-04-07 19:59:01
【问题描述】:
我有一个服务休息,我想做一个 POST 到一个 URL。当我与 POSTMAN 核对时,此 url 有效。
使用 POSTMAN,请求是
{
"username": "RenfeInbound",
"password": "renfeinbound"
}
这是我的春季服务休息
@Override
public RespuestaTransfesaBean peticionLogin(PeticionLoginTransfesa datosLogin) {
RespuestaTransfesaBean res = null;
try {
RestTemplate restTemplate = new RestTemplate();
HttpEntity<PeticionLoginTransfesa> request = new HttpEntity<>(datosLogin, getHttpHeaders());
res = restTemplate.postForObject(TRANSFESA_URL, request, RespuestaTransfesaBean.class);
TRANSFESA_URL 是我要执行请求的 URL。
datosLogin 是请求值
方法getHttpHeaders()是
private HttpHeaders getHttpHeaders() {
if (headers == null) {
headers = new HttpHeaders();
// headers.add("username", TRANSFESA_USER);
// headers.add("password", TRANSFESA_PASS);
headers.add("Content-Type", "application/json");
}
return headers;
}
当我执行请求时,控制台上出现以下错误
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://cloud-uat.transfesa.com/renfe-int-api/login": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:743)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:413)
at com.renfe.bcm.externas.transfesa.service.TransfesaServiceImpl.peticionLogin(TransfesaServiceImpl.java:35)
at com.renfe.bcm.externas.transfesa.restcontroller.TransfesaRestController.loginTransfesa(TransfesaRestController.java:23)
at com.renfe.bcm.externas.transfesa.restcontroller.TransfesaRestController$$FastClassBySpringCGLIB$$9aa75999.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
【问题讨论】:
-
我用邮递员试过了,它不起作用