Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The http utility class calls the Session cache

Shulou Source: shulou.com Published: 2022-06-03 03:28:17 10月03日 Update

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

Tags: Utf-8 parameters types tools caching Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info Redmi OPPO Reno macOS