I have a front with several options, these options can take you to a web page of cars, motorcycles, etc...
In the backEnd, said request is collected by post, some operations are carried out in said method and it calls "itself" again but by get to make the redirection2.
Here is the code that will receive the sensitive data and where it goes:
@RequestMapping(method = RequestMethod.POST, value = "/redirigir")
public ModelAndView redirigir (@RequestBody Redireccion destino, ModelMap model) throws JsonProcessingException {
log.info( "---> SERVICIO DE REDIRECCIÓN");
printParameters(destino);
String direccion = "";
if ("generar".equals(destino.getDestino())) {
direccion = urlGenerar;
}
if ("descarga".equals(destino.getDestino())) {
direccion = urlDescarga;
}
if ("".equals(direccion)) {
log.error( "---> El destino no es correcto");
// return new ResponseEntity<String>("", HttpStatus.NOT_FOUND);
} else {
log.info( "---> Redirigiendo.");
// return new ResponseEntity<String>(direccion.concat(destino.getUsuario()), HttpStatus.OK);
}
model.addAttribute("destino", destino);
return new ModelAndView("redirect:/gestUsr/redirigir2");
}
And here is the code that is called by the above code TO TAKE TO GOOGLE (when it works it will take where it needs to take.)
@RequestMapping(method = RequestMethod.GET, value = "/redirigir2")
public ModelAndView redirigir2 (ModelMap model) throws JsonProcessingException {
log.info( "---> SERVICIO DE REDIRECCIÓN2");
log.info (model.get("destino"));
return new ModelAndView("redirect:http://www.google.es");
// return new ResponseEntity<String>(direccion.concat(destino.getUsuario()), HttpStatus.OK);
}
It was done in this way, (service1-POST) calls (service2-Get) because when the redirection was attempted, the 405 OPTIONS jumped because it was a POST type, therefore, the redirection2 is made from a service that is by GET but it keeps giving problems.
edit:
I have set the method so that redirect2 is by RequestMethod.PUT and it doesn't work either.
I have changed the url for an Internal url of the project (it should manage Angular7)
return new ModelAndView("redirect:http://localhost:8080/****/pin");
It gives a nice 200 and everything you want, but it doesn't do the redirection, if I put the url of h ttp://localhost:8080/****/pin
obviously it takes me.
If you get an HTTP Status 200 but it's not being redirected, this means your request is an AJAX call. Surely, if you see the body of the response, you have all the HTML that forms the google.es website.
What you can do in this case is take the property
responseURL
of theXMLHttpRequest
. If there is a redirect, this property will have the final URL from which the data was requested. You can get it and updatewindow.location.href
with that value