美文网首页SAPSAP 实用篇SAP 修行
使用RestTemplate消费Hybris User API获

使用RestTemplate消费Hybris User API获

作者: 华山令狐冲 | 来源:发表于2019-12-19 15:35 被阅读0次

假设我用Hybris API调用的方式,返回Backoffice里维护的这个用户的全部信息:

使用下面这段代码:

public static void getUserInfo() {
        
        String responseStr = null;

        RestTemplate template = new RestTemplate();
        try {
            String token = "48a42ca3-b73a-4640-b690-1c393c0003ea";
            String url = "https://jerrywang.com:9002/rest/v2/electronics/users/cris.li03@qq.com";
            
            ResponseEntity<String> response = template.exchange(url, HttpMethod.GET, new HttpEntity<String>(createHeaders(token)), String.class);
            responseStr = response.getBody();
            System.out.println("response: " + responseStr);
        }catch (Exception e)
        {
            System.out.println("the exception message is: "+e.getMessage());
        }
    }

    private static HttpHeaders createHeaders(String token){
         return new HttpHeaders() {{
                 set( "Authorization", "Bearer " + token );
              }};
    }

测试结果:

要获取更多Jerry的原创文章,请关注公众号"汪子熙":


相关文章

网友评论

    本文标题:使用RestTemplate消费Hybris User API获

    本文链接:https://www.haomeiwen.com/subject/avnmnctx.html