The http utility class calls the Session cache
Package com.amway.pos.common.utils
Import org.springframework.core.io.FileSystemResource
Import org.springframework.http.HttpEntity
Import org.springframework.http.HttpHeaders
Import org.springframework.http.HttpMethod
Import org.springframework.http.MediaType
Import org.springframework.http.ResponseEntity
Import org.springframework.http.converter.HttpMessageConverter
Import org.springframework.http.converter.StringHttpMessageConverter
Import org.springframework.util.LinkedMultiValueMap
Import org.springframework.util.MultiValueMap
Import org.springframework.web.client.RestTemplate
Import org.springframework.web.context.request.RequestAttributes
Import org.springframework.web.context.request.RequestContextHolder
Import com.alibaba.fastjson.JSON
Import javax.servlet.http.HttpSession
Import java.io.File
Import java.io.UnsupportedEncodingException
Import java.net.URLDecoder
Import java.nio.charset.Charset
Import java.util.Collections
Import java.util.HashMap
Import java.util.List
Import java.util.Map
Public class HttpUtils {
Public static String httpPOST (String url,Object object) {String objectjson=JSON.toJSONString (object); Map map=JSON.parseObject (objectjson); HttpHeaders headers = new HttpHeaders (); / / define the request parameter type, here using json, so it is MediaType.APPLICATION_JSON RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes (); HttpSession session = (HttpSession) requestAttributes.resolveReference (RequestAttributes.REFERENCE_SESSION); headers.setContentType (MediaType.APPLICATION_JSON) Headers.set ("cookie", (String) session.getAttribute ("oldSysSessionId")); HttpEntity request = new HttpEntity (map, headers); RestTemplate restTemplate = getInstance ("utf-8"); ResponseEntity stringResponseEntity = restTemplate.postForEntity (url, request, String.class); Listlist = stringResponseEntity.getHeaders (). Get ("Set-Cookie"); if (list! = null&&list.size () > 0) {session.setAttribute ("oldSysSessionId", list.get (0)) } String jsonResult = stringResponseEntity.getBody (); return jsonResult;} public static RestTemplate getInstance (String charset) {RestTemplate restTemplate = new RestTemplate (); List