com.xiaoleilu.hutool
类 HttpUtil

java.lang.Object
  继承者 com.xiaoleilu.hutool.HttpUtil

public class HttpUtil
extends Object

Http请求工具类

作者:
xiaoleilu

字段摘要
static Pattern CHARSET_PATTERN
           
static String UNKNOW
          未知的标识
 
构造方法摘要
HttpUtil()
           
 
方法摘要
static String decode(String content, String charset)
          解码application/x-www-form-urlencoded字符
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 toParams(Map<String,Object> paramMap)
          将Map形式的Form表单数据转换为Url参数形式
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

UNKNOW

public static final String UNKNOW
未知的标识

另请参见:
常量字段值

CHARSET_PATTERN

public static final Pattern CHARSET_PATTERN
构造方法详细信息

HttpUtil

public HttpUtil()
方法详细信息

encode

public static String encode(String content,
                            String charset)
编码字符为 application/x-www-form-urlencoded

参数:
content - 被编码内容
返回:
编码后的字符

decode

public static String decode(String content,
                            String charset)
解码application/x-www-form-urlencoded字符

参数:
content - 被编码内容
返回:
编码后的字符

getClientIP

public static String getClientIP(javax.servlet.http.HttpServletRequest request)
获取客户端IP

参数:
request - 请求对象
返回:
IP地址

get

public static String get(String urlString,
                         String customCharset,
                         boolean isPassCodeError)
                  throws IOException
发送get请求

参数:
urlString - 网址
customCharset - 自定义请求字符集,如果字符集获取不到,使用此字符集
isPassCodeError - 是否跳过非200异常
返回:
返回内容,如果只检查状态码,正常只返回 "",不正常返回 null
抛出:
IOException

post

public static String post(String urlString,
                          Map<String,Object> paramMap,
                          String customCharset,
                          boolean isPassCodeError)
                   throws IOException
发送post请求

参数:
urlString - 网址
paramMap - post表单数据
customCharset - 自定义请求字符集,发送时使用此字符集,获取返回内容如果字符集获取不到,使用此字符集
isPassCodeError - 是否跳过非200异常
返回:
返回数据
抛出:
IOException

post

public static String post(String urlString,
                          String params,
                          String customCharset,
                          boolean isPassCodeError)
                   throws IOException
发送post请求

参数:
urlString - 网址
params - post表单数据
customCharset - 自定义请求字符集,发送时使用此字符集,获取返回内容如果字符集获取不到,使用此字符集
isPassCodeError - 是否跳过非200异常
返回:
返回数据
抛出:
IOException

downloadString

public static String downloadString(String url,
                                    String customCharset)
                             throws IOException
获得远程String

参数:
url - 请求的url
customCharset - 自定义的字符集
返回:
文本
抛出:
IOException

toParams

public static String toParams(Map<String,Object> paramMap)
将Map形式的Form表单数据转换为Url参数形式

参数:
paramMap - 表单数据
返回:
url参数


Copyright © 2014. All rights reserved.