图片下载
							parent
							
								
									2cc58f2c01
								
							
						
					
					
						commit
						4e3cd3237f
					
				
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -0,0 +1,79 @@ | |||||||
|  | package com.glxp.api.idc.utils; | ||||||
|  | 
 | ||||||
|  | import java.io.BufferedReader; | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStreamReader; | ||||||
|  | import java.util.Enumeration; | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.Map; | ||||||
|  | 
 | ||||||
|  | import javax.servlet.http.HttpServletRequest; | ||||||
|  | 
 | ||||||
|  | import org.springframework.http.HttpEntity; | ||||||
|  | import org.springframework.http.HttpHeaders; | ||||||
|  | import org.springframework.http.HttpMethod; | ||||||
|  | import org.springframework.stereotype.Service; | ||||||
|  | 
 | ||||||
|  | import com.alibaba.fastjson.JSON; | ||||||
|  | 
 | ||||||
|  | import cn.hutool.core.io.IoUtil; | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
|  | 
 | ||||||
|  | @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