gpt4 book ai didi

java - 从 Spring 支架 Controller 返回带有查询参数的响应

转载 作者:行者123 更新时间:2023-12-02 10:17:16 30 4
gpt4 key购买 nike

我想发送带有redirectUri 和查询参数的302 响应。我能够填充位置,但不确定如何将值作为查询参数包含在内以响应 Controller 。

我尝试向正文添加值,但我想在查询参数中发送它们。

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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com