Constructor and Description |
---|
CBConnection() |
Modifier and Type | Method and Description |
---|---|
CBConnection |
addDefaultMobileUserAgent()
添加默认手机代理(android)
|
CBConnection |
addDefaultPcUserAgent()
添加默认PC代理(osx)
|
CBConnection |
charset(java.lang.String charset)
设置编码
|
CBConnection |
connect(java.lang.String url)
连接地址
|
CBConnection |
connect(java.lang.String url,
java.lang.String charset)
连接地址
|
CBConnection |
cookie(java.lang.String cookie)
设置请求头部中的cookie
|
CBConnection |
data(java.util.Map<java.lang.String,java.lang.String> data)
设置请求数据
|
CBConnection |
data(java.lang.String... data)
设置请求数据
|
CBConnection |
data(java.lang.String data)
设置请求数据
|
CBConnection |
doNotTakeSessionForOnce()
此次连接不进行session信息携带
|
java.lang.String |
execute()
获取网页的内容
|
CBConnection |
followRedirects(boolean followRedirect)
设置请求属性
|
CBConnection |
header(java.util.Map<java.lang.String,java.lang.String> header)
添加请求头部,此方法将会清空之前所有已经设置的头部信息
|
CBConnection |
header(java.lang.String key,
java.lang.String value)
添加请求头部,仅仅添加一个,不会清空之前已经设置的头部
|
CBConnection |
host(java.lang.String host)
设置请求头部中的host
|
CBConnection |
keepCharset(boolean keepCharset)
保持请求编码集
|
CBConnection |
keepMethod(boolean keepMethod)
保持请求方式
|
CBConnection |
keepSession(boolean keepSession)
保持session,便于请求下个连接的时候不需要再次设置cookie等值
|
CBConnection |
method(CBMethod method)
请求方法
|
CBConnection |
referrer(java.lang.String referrer)
设置请求头部中的referer
|
protected CBConnection |
resetSomeState()
参数重置
其中timeout,cookie,keepSession不进行重置
|
void |
saveToFile(java.io.File file)
保存指定位置的文件
|
CBConnection |
timeout(int timeout)
设置请求连接与读取的超时时间
|
CBConnection |
userAgent(java.lang.String userAgent)
设置请求头部中的user agent
|
public CBConnection connect(java.lang.String url)
url
- urlpublic CBConnection connect(java.lang.String url, java.lang.String charset)
url
- urlcharset
- 编码public CBConnection keepCharset(boolean keepCharset)
keepCharset
- 保持编码集public CBConnection charset(java.lang.String charset)
charset
- 编码,默认编码UTF-8CBDefaultConfig
public CBConnection keepMethod(boolean keepMethod)
keepMethod
- 保持请求方式public CBConnection method(CBMethod method)
method
- 方法,默认GETCBMethod
,
CBDefaultConfig
public CBConnection cookie(java.lang.String cookie)
cookie
- cookiepublic CBConnection followRedirects(boolean followRedirect)
followRedirect
- 是否在301/302的时候继续请求public CBConnection timeout(int timeout)
timeout
- 时间,单位毫秒,默认30sCBDefaultConfig
public CBConnection host(java.lang.String host)
host
- hostpublic CBConnection referrer(java.lang.String referrer)
referrer
- 来源public CBConnection userAgent(java.lang.String userAgent)
userAgent
- uapublic CBConnection addDefaultPcUserAgent()
public CBConnection addDefaultMobileUserAgent()
public CBConnection header(java.util.Map<java.lang.String,java.lang.String> header)
header
- 请求头部header(String, String)
public CBConnection header(java.lang.String key, java.lang.String value)
key
- 请求头部名字value
- 请求头部值header(Map)
public CBConnection data(java.lang.String data)
data
- 表单数据,格式与url传递参数格式相同public CBConnection data(java.lang.String... data)
data
- 表单数据public CBConnection data(java.util.Map<java.lang.String,java.lang.String> data)
data
- 表单数据public CBConnection keepSession(boolean keepSession)
keepSession
- 保持sessionpublic CBConnection doNotTakeSessionForOnce()
public java.lang.String execute() throws java.io.IOException
java.io.IOException
- 异常protected CBConnection resetSomeState()
public void saveToFile(java.io.File file) throws java.io.IOException
file
- 保存文件java.io.IOException
- IO异常