mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复HttpUtil.decodeParams方法,判断是否x-www-form-urlencoded的模式
This commit is contained in:
@@ -615,7 +615,7 @@ public class HttpUtil {
|
||||
* @return 参数Map
|
||||
*/
|
||||
public static Map<String, List<String>> decodeParams(String paramsStr, String charset) {
|
||||
return decodeParams(paramsStr, CharsetUtil.charset(charset));
|
||||
return decodeParams(paramsStr, charset, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -624,10 +624,34 @@ public class HttpUtil {
|
||||
* @param paramsStr 参数字符串(或者带参数的Path)
|
||||
* @param charset 字符集
|
||||
* @return 参数Map
|
||||
*/
|
||||
public static Map<String, List<String>> decodeParams(String paramsStr, String charset, boolean isFormUrlEncoded) {
|
||||
return decodeParams(paramsStr, CharsetUtil.charset(charset), isFormUrlEncoded);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将URL QueryString参数解析为Map
|
||||
*
|
||||
* @param paramsStr 参数字符串(或者带参数的Path)
|
||||
* @param charset 字符集
|
||||
* @return 参数Map
|
||||
* @since 5.2.6
|
||||
*/
|
||||
public static Map<String, List<String>> decodeParams(String paramsStr, Charset charset) {
|
||||
final Map<CharSequence, CharSequence> queryMap = UrlQuery.of(paramsStr, charset).getQueryMap();
|
||||
return decodeParams(paramsStr, charset, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将URL参数解析为Map(也可以解析Post中的键值对参数)
|
||||
*
|
||||
* @param paramsStr 参数字符串(或者带参数的Path)
|
||||
* @param charset 字符集
|
||||
* @param isFormUrlEncoded 是否为x-www-form-urlencoded模式,此模式下空格会编码为'+'
|
||||
* @return 参数Map
|
||||
*/
|
||||
public static Map<String, List<String>> decodeParams(String paramsStr, Charset charset, boolean isFormUrlEncoded) {
|
||||
final Map<CharSequence, CharSequence> queryMap =
|
||||
UrlQuery.of(paramsStr, charset, true, isFormUrlEncoded).getQueryMap();
|
||||
if (MapUtil.isEmpty(queryMap)) {
|
||||
return MapUtil.empty();
|
||||
}
|
||||
|
@@ -331,7 +331,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
//解析URL中的参数
|
||||
final String query = getQuery();
|
||||
if(StrUtil.isNotBlank(query)){
|
||||
this.paramsCache.putAll(HttpUtil.decodeParams(query, charset));
|
||||
this.paramsCache.putAll(HttpUtil.decodeParams(query, charset, false));
|
||||
}
|
||||
|
||||
// 解析multipart中的参数
|
||||
@@ -341,7 +341,7 @@ public class HttpServerRequest extends HttpServerBase {
|
||||
// 解析body中的参数
|
||||
final String body = getBody();
|
||||
if(StrUtil.isNotBlank(body)){
|
||||
this.paramsCache.putAll(HttpUtil.decodeParams(body, charset));
|
||||
this.paramsCache.putAll(HttpUtil.decodeParams(body, charset, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user