com.diboot.core.util.HttpHelper Maven / Gradle / Ivy
/*
* Copyright (c) 2015-2020, www.dibo.ltd ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.diboot.core.util;
import com.diboot.core.config.Cons;
import lombok.extern.slf4j.Slf4j;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/**
* HTTP请求相关工具类
* @author [email protected]
* @version v2.0
* @date 2020/02/18
*/
@Slf4j
public class HttpHelper {
/***
* 构建请求参数Map
* @return
*/
public static Map buildParamsMap(HttpServletRequest request) {
Enumeration paramNames = request.getParameterNames();
if(paramNames.hasMoreElements() == false){
return Collections.emptyMap();
}
Map result = new HashMap<>();
try{
while (paramNames.hasMoreElements()){
String paramName = (String) paramNames.nextElement();
String[] values = request.getParameterValues(paramName);
if(V.notEmpty(values)){
if(values.length == 1){
if(V.notEmpty(values[0])){
String paramValue = java.net.URLDecoder.decode(values[0], com.diboot.core.config.Cons.CHARSET_UTF8);
result.put(paramName, paramValue);
}
}
else{
String[] valueArray = new String[values.length];
for(int i=0; i