Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The http utility class calls the Session cache

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report