我想发送带有redirectUri和查询参数的302响应。我能够填写位置,但不确定如何响应控制器将值包括为查询参数。
我试图将值添加到正文,但我想在查询参数中发送它们。
public ResponseEntity<Void> redirect(@RequestBody MultiValueMap<String,String> formVars, HttpServletResponse response) {
String clientId = formVars.getFirst(CLIENT_ID);
String redirectUri = formVars.getFirst(REDIRECT_URI);
String redirectToken = formVars.getFirst(REDIRECTION_TOKEN);
ResponseHandler<RedirectDto> redirectDtoResponseHandler = redirectService.redeemRedirectToken(redirectToken);
if (!redirectDtoResponseHandler.isPresent()) {
//handle error
}
redirectDtoResponseHandler.map(redirectDto -> toCookie(redirectDto.getCustomerSessionId()))
.ifPresent(response::addCookie);
URI uri = UriComponentsBuilder.fromHttpUrl(redirectUri).build().toUri();
//I'd like to add clientId as query param in this response?
return ResponseEntity.status(HttpStatus.FOUND).location(uri).build();
}
我想在此响应中添加clientId作为查询参数吗?
最佳答案
UriComponents uriComponents = UriComponentsBuilder.newInstance()
.scheme("http").host(redirectUri)
.path("/").query("clientId={keyword}").buildAndExpand(clientId);
关于java - 带有查询参数的 Spring 支架 Controller 的返回响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54594325/