public abstract class WebUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
buildForm(String baseUrl,
Map<String,String> parameters)
Build form string.
|
String |
buildForm(String baseUrl,
RequestParametersHolder requestHolder)
Build form string.
|
static String |
buildQuery(Map<String,String> params,
String charset)
Build query string.
|
static String |
decode(String value)
使用默认的UTF-8字符集反编码请求参数值。
|
static String |
decode(String value,
String charset)
使用指定的字符集反编码请求参数值。
|
static String |
doGet(String url,
Map<String,String> params)
执行HTTP GET请求。
|
static String |
doGet(String url,
Map<String,String> params,
String charset)
执行HTTP GET请求。
|
static String |
doPost(String url,
Map<String,String> params,
Map<String,FileItem> fileParams,
String charset,
int connectTimeout,
int readTimeout,
String proxyHost,
int proxyPort)
执行带文件上传的HTTP POST请求。
|
static String |
doPost(String url,
Map<String,String> params,
String charset,
int connectTimeout,
int readTimeout,
String proxyHost,
int proxyPort)
执行HTTP POST请求,可使用代理proxy。
|
static String |
doPost(String url,
String ctype,
byte[] content,
int connectTimeout,
int readTimeout,
String proxyHost,
int proxyPort)
执行HTTP POST请求。
|
static String |
encode(String value)
使用默认的UTF-8字符集编码请求参数值。
|
static String |
encode(String value,
String charset)
使用指定的字符集编码请求参数值。
|
protected static String |
getResponseAsString(HttpURLConnection conn)
Gets response as string.
|
static Map<String,String> |
splitUrlQuery(String query)
从URL中提取所有的参数。
|
public static String doPost(String url, Map<String,String> params, String charset, int connectTimeout, int readTimeout, String proxyHost, int proxyPort) throws IOException
url
- 请求地址params
- 请求参数charset
- 字符集,如UTF-8, GBK, GB2312connectTimeout
- 连接超时时间readTimeout
- 请求超时时间proxyHost
- 代理host,传null表示不使用代理proxyPort
- 代理端口,传0表示不使用代理IOException
- the io exceptionpublic static String doPost(String url, String ctype, byte[] content, int connectTimeout, int readTimeout, String proxyHost, int proxyPort) throws IOException
url
- 请求地址ctype
- 请求类型content
- 请求字节数组connectTimeout
- 连接超时时间readTimeout
- 请求超时时间proxyHost
- 代理host,传null表示不使用代理proxyPort
- 代理端口,传0表示不使用代理IOException
- the io exceptionpublic static String doPost(String url, Map<String,String> params, Map<String,FileItem> fileParams, String charset, int connectTimeout, int readTimeout, String proxyHost, int proxyPort) throws IOException
url
- 请求地址params
- 文本请求参数fileParams
- 文件请求参数charset
- 字符集,如UTF-8, GBK, GB2312connectTimeout
- 连接超时时间readTimeout
- 请求超时时间proxyHost
- 代理host,传null表示不使用代理proxyPort
- 代理端口,传0表示不使用代理IOException
- the io exceptionpublic static String doGet(String url, Map<String,String> params) throws IOException
url
- 请求地址params
- 请求参数IOException
- the io exceptionpublic static String doGet(String url, Map<String,String> params, String charset) throws IOException
url
- 请求地址params
- 请求参数charset
- 字符集,如UTF-8, GBK, GB2312IOException
- the io exceptionpublic static String buildQuery(Map<String,String> params, String charset) throws IOException
params
- the paramscharset
- the charsetIOException
- the io exceptionprotected static String getResponseAsString(HttpURLConnection conn) throws IOException
conn
- the connIOException
- the io exceptionpublic static String decode(String value)
value
- 参数值public static String encode(String value)
value
- 参数值public static String decode(String value, String charset)
value
- 参数值charset
- 字符集public static String encode(String value, String charset)
value
- 参数值charset
- 字符集public static Map<String,String> splitUrlQuery(String query)
query
- URL地址public String buildForm(String baseUrl, RequestParametersHolder requestHolder)
baseUrl
- the base urlrequestHolder
- the request holderCopyright © 2018. All rights reserved.