public final class CUrl extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
CUrl.CookieStore |
static class |
CUrl.FileIO |
static interface |
CUrl.IO |
static class |
CUrl.MemIO |
static class |
CUrl.Recoverable |
static interface |
CUrl.Resolver<T> |
static class |
CUrl.ToStringResolver |
static class |
CUrl.WrappedIO |
| 限定符和类型 | 字段和说明 |
|---|---|
static CUrl.ToStringResolver |
GBK |
static CUrl.ToStringResolver |
ISO_8859_1 |
static CUrl.Resolver<byte[]> |
RAW |
static CUrl.ToStringResolver |
UTF8 |
| 限定符和类型 | 方法和说明 |
|---|---|
CUrl |
cookie(CUrl.IO input)
读取数据IO并添加请求Cookie。
|
CUrl |
cookie(String input)
添加请求Cookie
Add custom Cookies in request
|
CUrl |
cookieJar(CUrl.IO output)
输出Cookie到给定的数据IO
Output Cookie to given IO object
|
CUrl |
cookieJar(String output)
输出Cookie到给定的文件
Output Cookie to given file path
|
CUrl |
data(CUrl.IO input,
boolean binary)
从input中读取数据作为post数据
Read data from input and use as post data
|
CUrl |
data(String data)
Add post data.
|
CUrl |
data(String data,
boolean raw)
Add post data.
|
CUrl |
data(String data,
String charset)
添加urlencode的post数据
Add URL-encoded post data
|
CUrl |
dumpHeader(CUrl.IO output)
倾印原始响应头到给定的数据IO
|
CUrl |
dumpHeader(String output)
倾印原始响应头到给定的文件
Dump raw response headers to specified file path
|
byte[] |
exec()
解析参数,执行请求,返回原始字节数组
Parse options and execute the request, return raw response.
|
<T> T |
exec(CUrl.Resolver<T> resolver,
T fallback)
解析参数并执行请求
默认仅包含应答数据。
|
String |
exec(String encoding)
解析参数,执行请求,并将标准输出以给定的encoding解码为字符串
Parse options and execute the request。
|
CUrl |
form(String formString)
发起post文件上传,添加1~N个非文件表单项,注意此方法不对'@'进行特殊处理
|
CUrl |
form(String name,
CUrl.IO input)
发起post文件上传,添加一个文件上传的表单项
Issue a form based upload and add a file item
|
CUrl |
form(String name,
String content)
发起post文件上传,添加一个表单项
Issue a form based upload and add a form item
|
static CookieStore |
getCookieStore() |
long |
getExecTime()
Get total time-consuming including retrying in millisecond.
|
Map<String,String> |
getHeaders()
Get request headers, filled after exec.
|
int |
getHttpCode()
Get HTTP status code of last response, i.e. 200, 302 etc.
|
List<URL> |
getLocations()
Get all destination URLs including redirection(s) in one request.
|
List<String> |
getOptions()
Get all options, filled after exec.
|
List<List<String[]>> |
getResponseHeaders()
Get headers of all responses including redirection(s) in one request.
|
<T> T |
getStdout(CUrl.Resolver<T> resolver,
T fallback) |
Map<String,String> |
getTags() |
CUrl |
header(String headerLine)
Add a custom request header
|
CUrl |
headers(Map<String,?> headers) |
CUrl |
insecure()
Allow insecure server connections when using HTTPS
|
CUrl |
io(String key,
CUrl.IO io)
添加一个数据IO,可作为数据输入或数据输出,在--data等参数值中引用
|
static void |
loadCookies(CUrl.IO input)
Load cookies from the specified IO object to the cookie-store binding with current thread
|
CUrl |
location()
Follow redirection automatically, false be default.
|
static void |
main(String[] args) |
CUrl |
opt(String... options)
Specify 0~N options, please refer to https://curl.haxx.se/docs/manpage.html
Note: the option name and corresponding value must be divided into two arguments, rather than one single string seperated by space
|
CUrl |
output(CUrl.IO output)
输出应答数据到给定数据IO
|
CUrl |
output(String output)
输出应答数据到给定文件。
|
CUrl |
proxy(String host,
int port)
Specify the proxy server
|
CUrl |
retry(int retry,
float retryDelay,
float retryMaxTime)
Specify retry related options, default values are 0
|
static void |
saveCookies(CUrl.IO output)
Save all cookies binding with current thread to the specified IO object.
|
CUrl |
stderr(CUrl.IO output)
重定向标准错误输出到给定的数据IO
|
CUrl |
stderr(String output)
重定向标准错误输出到给定的文件
Redirect stderr to specified file path, use '-' for stdout
|
CUrl |
timeout(float connectTimeoutSeconds,
float readTimeoutSeconds)
Specify timeout, default values are 0
|
String |
toString()
Get all options as CURL command-line
|
CUrl |
url(String url) |
public static final CUrl.Resolver<byte[]> RAW
public static final CUrl.ToStringResolver UTF8
public static final CUrl.ToStringResolver GBK
public static final CUrl.ToStringResolver ISO_8859_1
public CUrl()
public CUrl(String url)
public final CUrl opt(String... options)
options - e.g. opt("-H", "X-Requested-With: XMLHttpRequest")public final CUrl location()
public final CUrl insecure()
public final CUrl retry(int retry, float retryDelay, float retryMaxTime)
retry - Retry timesretryDelay - The interval between two retries (in second)retryMaxTime - The max retry time in second, 0 means infinitepublic final CUrl timeout(float connectTimeoutSeconds, float readTimeoutSeconds)
connectTimeoutSeconds - Connection timeout in secondreadTimeoutSeconds - Read timeout in secondpublic final CUrl header(String headerLine)
headerLine - Syntax:
"Host: baidu.com": add/set a request header-value pair
"Accept:": delete a previously added request header
"X-Custom-Header;": add/set a request header with empty valuepublic final CUrl data(String data)
data - if data start with '@', then the following part will be treated as file pathpublic final CUrl data(String data, boolean raw)
data - 如果data以'@'开头且raw=false,则后面部分作为文件名,数据由该文件读入raw - 如为真则不对'@'做特殊处理public final CUrl data(CUrl.IO input, boolean binary)
input - binary - 如为真则读取数据中的回车换行符会保留,否则会被删除public final CUrl data(String data, String charset)
data, - 语法如下/syntax:
"content": 如content中不包含'=', '@',则直接把整个content作为数据整体进行urlencode
"=content": '='后面的content整体进行urlencode,不处理特殊字符,第一个'='不包含在数据内容中
"name1=value1[&name2=value2...]": 按照'&'拆分后,对每个值进行urlencode,注意键不进行处理
"@filename": '@'后面的部分作为文件名,从文件中读取内容并进行urlencode,回车换行保留
"name@filename": 读取'@'后面的文件内容作为值进行urlencode,并以name为键charset - urlencode使用的字符集,如为null则默认使用"UTF-8"public final CUrl form(String name, String content)
name - 表单项名content - 如首字母为'@'或'<'则从指定的文件读取数据进行上传。
'@'和'<'的区别在于,'@'的文件内容作为文件附件上传,'<'的文件内容作为普通表单项public final CUrl form(String name, CUrl.IO input)
name - 表单项名input - 上传的数据IOpublic final CUrl form(String formString)
formString - 语法为"name1=value1[&name2=value2...]"public final CUrl cookieJar(String output)
output - 文件路径,使用'-'表示输出到标准输出。默认不输出public final CUrl cookieJar(CUrl.IO output)
output - 数据IO,注意cookieJar的输出会清除output中的原有内容public final CUrl cookie(String input)
input - 格式为"NAME1=VALUE1; NAME2=VALUE2"的Cookie键值对。
如字串中不包含'='则作为输入文件名;
如传入空字符串则仅清空当前线程的Cookiepublic final CUrl cookie(CUrl.IO input)
input - public final CUrl dumpHeader(String output)
output - 输出文件的路径,使用'-'表示输出到标准输出。默认不输出。public final CUrl stderr(String output)
output - 输出文件路径。使用'-'表示输出到标准输出。默认输出到标准输出。public final CUrl output(String output)
output - 输出文件路径。使用'-'表示输出到标准输出。默认输出到标准输出。public final CUrl io(String key, CUrl.IO io)
key - io - public static CookieStore getCookieStore()
public static void saveCookies(CUrl.IO output)
output - public static void loadCookies(CUrl.IO input)
input - public final String toString()
public final List<String> getOptions()
public final List<List<String[]>> getResponseHeaders()
public final long getExecTime()
public final int getHttpCode()
public final <T> T getStdout(CUrl.Resolver<T> resolver, T fallback)
public final List<URL> getLocations()
public final String exec(String encoding)
encoding,如传入null则默认使用"UTF-8" - public final byte[] exec()
public final <T> T exec(CUrl.Resolver<T> resolver, T fallback)
resolver - 输出解析器fallback - 默认返回值public static void main(String[] args)
Copyright © 2018. All rights reserved.