public class HttpUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static Pattern |
CHARSET_PATTERN |
static String |
UNKNOW
未知的标识
|
| 构造器和说明 |
|---|
HttpUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
decode(String content,
String charset)
解码application/x-www-form-urlencoded字符
|
static Map<String,List<String>> |
decodeParams(String paramsStr,
String charset)
将URL参数解析为Map(也可以解析Post中的键值对参数)
|
static String |
downloadString(String url,
String customCharset)
获得远程String
|
static String |
encode(String content,
String charset)
编码字符为 application/x-www-form-urlencoded
|
static String |
get(String urlString,
String customCharset,
boolean isPassCodeError)
发送get请求
|
static String |
getClientIP(javax.servlet.http.HttpServletRequest request)
获取客户端IP
|
static String |
post(String urlString,
Map<String,Object> paramMap,
String customCharset,
boolean isPassCodeError)
发送post请求
|
static String |
post(String urlString,
String params,
String customCharset,
boolean isPassCodeError)
发送post请求
|
static String |
request(String method,
String urlString,
String customCharset,
boolean isPassCodeError,
Map<String,Object> headers)
请求
|
static String |
toParams(Map<String,Object> paramMap)
将Map形式的Form表单数据转换为Url参数形式
|
public static final Pattern CHARSET_PATTERN
public static String encode(String content, String charset)
content - 被编码内容public static String decode(String content, String charset)
content - 被编码内容public static String getClientIP(javax.servlet.http.HttpServletRequest request)
request - 请求对象public static String request(String method, String urlString, String customCharset, boolean isPassCodeError, Map<String,Object> headers) throws IOException
method - 方法urlString - URLcustomCharset - 自定义的编码isPassCodeError - 是否跳过非200异常headers - 请求头IOExceptionpublic static String get(String urlString, String customCharset, boolean isPassCodeError) throws IOException
urlString - 网址customCharset - 自定义请求字符集,如果字符集获取不到,使用此字符集isPassCodeError - 是否跳过非200异常IOExceptionpublic static String post(String urlString, Map<String,Object> paramMap, String customCharset, boolean isPassCodeError) throws IOException
urlString - 网址paramMap - post表单数据customCharset - 自定义请求字符集,发送时使用此字符集,获取返回内容如果字符集获取不到,使用此字符集isPassCodeError - 是否跳过非200异常IOExceptionpublic static String post(String urlString, String params, String customCharset, boolean isPassCodeError) throws IOException
urlString - 网址params - post表单数据customCharset - 自定义请求字符集,发送时使用此字符集,获取返回内容如果字符集获取不到,使用此字符集isPassCodeError - 是否跳过非200异常IOExceptionpublic static String downloadString(String url, String customCharset) throws IOException
url - 请求的urlcustomCharset - 自定义的字符集IOExceptionpublic static String toParams(Map<String,Object> paramMap)
paramMap - 表单数据Copyright © 2015. All rights reserved.