无法从WebClient Post API获得正确的响应。它是打印软件包名称和十六进制字符串。如果我使用custome pojo,抛出异常

发布于 2025-02-09 07:37:57 字数 2840 浏览 1 评论 0原文

我的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

enter image description here

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.

enter image description here

I only need to extract accesstoken from response. how can I get the same?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文