public class HttpUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static Pattern |
CHARSET_PATTERN |
| 构造器和说明 |
|---|
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)
发送get请求
|
static String |
getCharset(HttpURLConnection conn)
从Http连接的头信息中获得字符集
|
static String |
getClientIP(javax.servlet.http.HttpServletRequest request)
获取客户端IP
|
static String |
getMimeType(String filePath)
根据文件扩展名获得MimeType
|
static String |
getString(InputStream in,
String charset,
boolean isGetCharsetFromContent)
从流中读取内容
|
static boolean |
isHttps(String url)
检测是否https
|
static boolean |
isUnknow(String checkString)
检测给定字符串是否为未知,多用于检测HTTP请求相关
|
static String |
post(String urlString,
Map<String,Object> paramMap)
发送post请求
|
static String |
post(String urlString,
String params)
发送post请求
|
static String |
toParams(Map<String,Object> paramMap)
将Map形式的Form表单数据转换为Url参数形式
|
static String |
urlWithForm(String url,
Map<String,Object> form)
将表单数据加到URL中(用于GET表单提交)
|
static String |
urlWithForm(String url,
String queryString)
将表单数据字符串加到URL中(用于GET表单提交)
|
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 boolean isHttps(String url)
url - URLpublic static String get(String urlString, String customCharset) throws IOException
urlString - 网址customCharset - 自定义请求字符集,如果字符集获取不到,使用此字符集IOExceptionpublic static String post(String urlString, Map<String,Object> paramMap) throws IOException
urlString - 网址paramMap - post表单数据IOExceptionpublic static String post(String urlString, String params) throws IOException
urlString - 网址params - post表单数据IOExceptionpublic static String downloadString(String url, String customCharset) throws IOException
url - 请求的urlcustomCharset - 自定义的字符集IOExceptionpublic static String toParams(Map<String,Object> paramMap)
paramMap - 表单数据public static Map<String,List<String>> decodeParams(String paramsStr, String charset)
paramsStr - 参数字符串(或者带参数的Path)charset - 字符集public static String urlWithForm(String url, Map<String,Object> form)
url - URLform - 表单数据public static String urlWithForm(String url, String queryString)
url - URLqueryString - 表单数据字符串public static String getCharset(HttpURLConnection conn)
conn - HTTP连接对象public static boolean isUnknow(String checkString)
checkString - 被检测的字符串public static String getString(InputStream in, String charset, boolean isGetCharsetFromContent) throws IOException
in - 输入流charset - 字符集IOExceptionCopyright © 2015. All rights reserved.