Merge remote-tracking branch 'origin/master'
						commit
						9a5f78c42b
					
				| @ -0,0 +1,77 @@ | ||||
| package com.glxp.sale.admin.idc.utils; | ||||
| 
 | ||||
| import cn.hutool.core.io.IoUtil; | ||||
| import com.alibaba.fastjson.JSON; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.http.HttpEntity; | ||||
| import org.springframework.http.HttpHeaders; | ||||
| import org.springframework.http.HttpMethod; | ||||
| import org.springframework.stereotype.Service; | ||||
| 
 | ||||
| import javax.annotation.Resource; | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import java.io.BufferedReader; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStreamReader; | ||||
| import java.util.Enumeration; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| @Slf4j | ||||
| @Service | ||||
| public class UriUtils { | ||||
| 
 | ||||
|     public String parseUri(String url) { | ||||
|         String uri = url; | ||||
|         int a1 = uri.indexOf("://"); | ||||
|         int a2 = 0; | ||||
|         if (a1 > 0) { | ||||
|             a2 = uri.indexOf("/", a1 + 4); | ||||
|             if (a2 > 0) { | ||||
|                 uri = uri.substring(a2 + 1); | ||||
|             } | ||||
|         } | ||||
|         return uri; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     public HttpEntity<String> buildHeader(HttpServletRequest request) { | ||||
| 
 | ||||
|         log.info(request.getMethod()); | ||||
|         String bodyContent = ""; | ||||
|         Map<String, Object> headerParam = new HashMap<>(); | ||||
|         if (request.getMethod().equals(HttpMethod.GET)) { | ||||
|             Map<String, Object> bodyParam = new HashMap<String, Object>(); | ||||
|             Enumeration pNames = request.getParameterNames(); | ||||
|             while (pNames.hasMoreElements()) { | ||||
|                 String name = (String) pNames.nextElement(); | ||||
|                 String value = request.getParameter(name); | ||||
|                 bodyParam.put(name, value); | ||||
|             } | ||||
| 
 | ||||
|             bodyContent = JSON.toJSONString(bodyParam); | ||||
|         } else { | ||||
|             BufferedReader reader = null; | ||||
|             try { | ||||
|                 reader = new BufferedReader(new InputStreamReader(request.getInputStream())); | ||||
|                 bodyContent = IoUtil.read(reader); | ||||
|                 log.info(bodyContent); | ||||
|             } catch (IOException e) { | ||||
|                 e.printStackTrace(); | ||||
|             } | ||||
|         } | ||||
|         HttpHeaders headers = new HttpHeaders(); | ||||
|         Enumeration<String> enumeration = request.getHeaderNames(); | ||||
|         while (enumeration.hasMoreElements()) { | ||||
|             String name = enumeration.nextElement(); | ||||
|             String value = request.getHeader(name); | ||||
|             headerParam.put(name, value); | ||||
|             headers.add(name, value); | ||||
|         } | ||||
|         //headers.add("Content-Type", "application/json;charset=UTF-8");
 | ||||
|         HttpEntity<String> http = new HttpEntity<>(bodyContent, headers); | ||||
|         return http; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
					Loading…
					
					
				
		Reference in New Issue