标签:method hang user == 请求 value add control util
1、get请求带Cookie
String url = Config.XXX_BASE_URL + "/userlevel?inviterId=" + invit1; String restInfo = MessageFormat.format("url:{0}, inviterId:{1}", url, invit1); UtilFunctions.log.info("UserController#register call rest api info, " + restInfo); HttpHeaders requestHeaders = new HttpHeaders(); List<String> cookieList = UtilFunctions.getCookieList(request); requestHeaders.put("Cookie", cookieList); HttpEntity<String> requestEntity = new HttpEntity<String>(null, requestHeaders); restTemplate.exchange(url, HttpMethod.GET, requestEntity, JSONObject.class).getBody();
public static List<String> getCookieList(HttpServletRequest request) { List<String> cookieList = new ArrayList<>(); Cookie[] cookies = request.getCookies(); if (cookies == null || cookies.length == 0) { return cookieList; } for (Cookie cookie : cookies) { cookieList.add(cookie.getName() + "=" + cookie.getValue()); } return cookieList; }
标签:method hang user == 请求 value add control util
原文地址:https://www.cnblogs.com/xy-ouyang/p/10831588.html