无法从WebClient Post API获得正确的响应。它是打印软件包名称和十六进制字符串。如果我使用custome pojo,抛出异常
我的API返回以下响应
中消费时
public static String accessToken(String jwtToken) {
WebClient webClient = WebClient.create();
final WebClient.ResponseSpec response = webClient.post()
.uri(UriComponentsBuilder.fromUriString("https://account-d.docusign.com/oauth/token")
.queryParam("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
.queryParam("assertion", jwtToken)
.toUriString())
.retrieve();
System.out.println(response);
return response.toString();
}
但是当我从WebClient
响应>响应
org.springframework.web.reactive.function.client.DefaultWebClient$DefaultResponseSpec@7f0393b5
,我该如何使响应正确?
当我创建Custome Pojo课程
public class JwtToken {
private String access_token;
private String token_type;
private Integer expires_in;
private String scope;
@Override
public String toString() {
return access_token;
}
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public String getToken_type() {
return token_type;
}
public void setToken_type(String token_type) {
this.token_type = token_type;
}
public Integer getExpires_in() {
return expires_in;
}
public void setExpires_in(Integer expires_in) {
this.expires_in = expires_in;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}
并像下面一样使用它时,
public static String accessToken(String jwtToken) {
WebClient webClient = WebClient.create();
final JwtToken response = webClient.post()
.uri(UriComponentsBuilder.fromUriString("https://account-d.docusign.com/oauth/token")
.queryParam("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
.queryParam("assertion", jwtToken)
.toUriString())
.retrieve()
.bodyToMono(JwtToken.class)
.block();
System.out.println(response);
return response.toString();
}
它像下面一样使用了例外。
我只需要从响应中提取访问。我怎么能相同?
My API returns below response
But when I am consuming from webclient
public static String accessToken(String jwtToken) {
WebClient webClient = WebClient.create();
final WebClient.ResponseSpec response = webClient.post()
.uri(UriComponentsBuilder.fromUriString("https://account-d.docusign.com/oauth/token")
.queryParam("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
.queryParam("assertion", jwtToken)
.toUriString())
.retrieve();
System.out.println(response);
return response.toString();
}
response
is
org.springframework.web.reactive.function.client.DefaultWebClient$DefaultResponseSpec@7f0393b5
how can I make the response proper?
when I created custome POJO class
public class JwtToken {
private String access_token;
private String token_type;
private Integer expires_in;
private String scope;
@Override
public String toString() {
return access_token;
}
public String getAccess_token() {
return access_token;
}
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public String getToken_type() {
return token_type;
}
public void setToken_type(String token_type) {
this.token_type = token_type;
}
public Integer getExpires_in() {
return expires_in;
}
public void setExpires_in(Integer expires_in) {
this.expires_in = expires_in;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
}
and use it like below and used like below
public static String accessToken(String jwtToken) {
WebClient webClient = WebClient.create();
final JwtToken response = webClient.post()
.uri(UriComponentsBuilder.fromUriString("https://account-d.docusign.com/oauth/token")
.queryParam("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
.queryParam("assertion", jwtToken)
.toUriString())
.retrieve()
.bodyToMono(JwtToken.class)
.block();
System.out.println(response);
return response.toString();
}
it is throwing exception.
I only need to extract accesstoken from response. how can I get the same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论