public class HttpUtils
extends java.lang.Object
HttpCache
httpGet(HttpRequest)
http get synchronoushttpGet(String)
http get synchronoushttpGetString(String)
http get synchronous, response is StringhttpGet(HttpRequest, HttpListener)
http get asynchronoushttpGet(String, HttpListener)
http get asynchronousModifier and Type | Class and Description |
---|---|
static class |
HttpUtils.HttpListener
HttpListener, can do something before or after HttpGet
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EQUAL_SIGN
equal sign
|
static java.lang.String |
PARAMETERS_SEPARATOR
parameters separator
|
static java.lang.String |
PATHS_SEPARATOR
paths separator
|
static java.lang.String |
URL_AND_PARA_SEPARATOR
url and para separator
|
Constructor and Description |
---|
HttpUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
appendParaToUrl(java.lang.String url,
java.lang.String paraKey,
java.lang.String paraValue)
append a key and value pair to url
|
static java.lang.String |
getUrlWithParas(java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> parasMap)
join url and paras
getUrlWithParas(null, {(a, b)}) = "?
|
static java.lang.String |
getUrlWithValueEncodeParas(java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> parasMap)
join url and encoded paras
|
static HttpResponse |
httpGet(HttpRequest request)
http get synchronous
use gzip compression default
use bufferedReader to improve the reading speed
|
static void |
httpGet(HttpRequest request,
HttpUtils.HttpListener listener)
http get asynchronous
It gets data or network asynchronous.
|
static HttpResponse |
httpGet(java.lang.String httpUrl)
http get synchronous
|
static void |
httpGet(java.lang.String url,
HttpUtils.HttpListener listener)
http get asynchronous
It gets data from network asynchronous.
|
static java.lang.String |
httpGetString(HttpRequest request)
http get synchronous
|
static java.lang.String |
httpGetString(java.lang.String httpUrl)
http get synchronous
|
static HttpResponse |
httpPost(HttpRequest request)
http post
use gzip compression default
use bufferedReader to improve the reading speed
|
static HttpResponse |
httpPost(java.lang.String httpUrl)
http post
|
static java.lang.String |
httpPostString(java.lang.String httpUrl)
http post
|
static java.lang.String |
httpPostString(java.lang.String httpUrl,
java.util.Map<java.lang.String,java.lang.String> parasMap)
http post
|
static java.lang.String |
joinParas(java.util.Map<java.lang.String,java.lang.String> parasMap)
join paras
|
static java.lang.String |
joinParasWithEncodedValue(java.util.Map<java.lang.String,java.lang.String> parasMap)
join paras with encoded value
|
static long |
parseGmtTime(java.lang.String gmtTime)
parse gmt time to long
|
static void |
setURLConnection(java.util.Map<java.lang.String,java.lang.String> requestProperties,
java.net.HttpURLConnection urlConnection)
set HttpURLConnection property
|
public static final java.lang.String URL_AND_PARA_SEPARATOR
public static final java.lang.String PARAMETERS_SEPARATOR
public static final java.lang.String PATHS_SEPARATOR
public static final java.lang.String EQUAL_SIGN
public static HttpResponse httpGet(HttpRequest request)
request
- public static HttpResponse httpGet(java.lang.String httpUrl)
httpUrl
- httpGet(HttpRequest)
public static java.lang.String httpGetString(HttpRequest request)
request
- httpGet(HttpRequest)
public static java.lang.String httpGetString(java.lang.String httpUrl)
httpUrl
- httpGet(HttpRequest)
public static void httpGet(java.lang.String url, HttpUtils.HttpListener listener)
httpGet(HttpRequest)
or httpGetString(HttpRequest)
url
- listener
- listener which can do something before or after HttpGet. this can be null if you not want to do
somethingpublic static void httpGet(HttpRequest request, HttpUtils.HttpListener listener)
HttpCache.httpGet(HttpRequest)
or
HttpCache.httpGetString(HttpRequest)
request
- listener
- listener which can do something before or after HttpGet. this can be null if you not want to do
somethingpublic static HttpResponse httpPost(HttpRequest request)
httpUrl
- paras
- public static HttpResponse httpPost(java.lang.String httpUrl)
httpUrl
- httpPost(HttpRequest)
public static java.lang.String httpPostString(java.lang.String httpUrl)
httpUrl
- httpPost(HttpRequest)
public static java.lang.String httpPostString(java.lang.String httpUrl, java.util.Map<java.lang.String,java.lang.String> parasMap)
httpUrl
- parasMap
- paras map, key is para name, value is para value. will be transfrom to String by
joinParas(Map)
httpPost(HttpRequest)
public static java.lang.String getUrlWithParas(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> parasMap)
getUrlWithParas(null, {(a, b)}) = "?a=b"; getUrlWithParas("baidu.com", {}) = "baidu.com"; getUrlWithParas("baidu.com", {(a, b), (i, j)}) = "baidu.com?a=b&i=j"; getUrlWithParas("baidu.com", {(a, b), (i, j), (c, d)}) = "baidu.com?a=b&i=j&c=d";
url
- urlparasMap
- paras map, key is para name, value is para valuepublic static java.lang.String getUrlWithValueEncodeParas(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> parasMap)
url
- parasMap
- getUrlWithParas(String, Map)
,
StringUtils.utf8Encode(String)
public static java.lang.String joinParas(java.util.Map<java.lang.String,java.lang.String> parasMap)
parasMap
- paras map, key is para name, value is para valueEQUAL_SIGN
, join keys with PARAMETERS_SEPARATOR
public static java.lang.String joinParasWithEncodedValue(java.util.Map<java.lang.String,java.lang.String> parasMap)
parasMap
- joinParas(Map)
,
StringUtils.utf8Encode(String)
public static java.lang.String appendParaToUrl(java.lang.String url, java.lang.String paraKey, java.lang.String paraValue)
url
- paraKey
- paraValue
- public static long parseGmtTime(java.lang.String gmtTime)
gmtTime
- likes Thu, 11 Apr 2013 10:20:30 GMTpublic static void setURLConnection(java.util.Map<java.lang.String,java.lang.String> requestProperties, java.net.HttpURLConnection urlConnection)
requestProperties
- urlConnection
-