使用RestTemplate消费Hybris User API获取指定用户的信息
生活随笔
收集整理的這篇文章主要介紹了
使用RestTemplate消费Hybris User API获取指定用户的信息
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
假設我用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获取指定用户的信息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hybris Storefront里如何
- 下一篇: git stash命令的用法