【发布时间】:2017-11-30 06:46:26
【问题描述】:
我有以下代码:
@RequestMapping(
consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE},
path = "api/api1",
method = RequestMethod.POST,
produces = MediaType.ALL_VALUE
)
public ResponseEntity<?> api1CallBack(@RequestBody String requestBody, HttpServletRequest request) throws IOException, GeneralSecurityException, URISyntaxException {
String response="{SOME_JSON}";
URI callbackURL = new URI("http://otherAPIEnv/api2");
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(callbackURL);
return new ResponseEntity<String>(response,httpHeaders, HttpStatus.OK);
}
我尝试了上面的代码,但是当我通过 curl 访问 api1 时,我在同一台机器上得到了响应,但我希望将响应重定向到 otherAPIEnv 机器上的 api2。
有人可以建议如何实现这种请求和响应吗?
【问题讨论】:
标签: java spring spring-boot response.redirect