| 程序包 | 说明 |
|---|---|
| org.dromara.hutool.http |
Hutool-http针对JDK的HttpUrlConnection做一层封装,简化了HTTPS请求、文件上传、Cookie记忆等操作,使Http请求变得无比简单。
|
| org.dromara.hutool.http.client |
HTTP请求客户端封装,请求过程如下:
Server
^ |
| v
Request Response
^ |
| v
ClientEngine
|
| org.dromara.hutool.http.client.engine |
Http客户端引擎实现
|
| org.dromara.hutool.http.client.engine.httpclient4 |
Apache HttpClient 4.x实现
文档见:https://hc.apache.org/httpcomponents-client-4.5.x/index.html |
| org.dromara.hutool.http.client.engine.httpclient5 |
Apache HttpClient 5.1.x实现
文档见:https://hc.apache.org/httpcomponents-client-5.1.x/index.html |
| org.dromara.hutool.http.client.engine.jdk |
基于JDK的HttpUrlConnection封装的HTTP客户端
|
| org.dromara.hutool.http.client.engine.okhttp |
OKHttp3封装
文档见:https://square.github.io/okhttp/ |
| 限定符和类型 | 方法和说明 |
|---|---|
static Response |
HttpUtil.send(Request request)
使用默认HTTP引擎,发送HTTP请求
|
| 限定符和类型 | 方法和说明 |
|---|---|
Request |
Request.body(HttpBody body)
添加请求体
|
Request |
Request.body(String body)
添加字符串请求体
|
Request |
Request.charset(Charset charset)
设置编码
|
Request |
Request.form(Map<String,Object> formMap)
添加请求表单内容
|
Request |
Request.header(String name,
String value,
boolean isOverride)
设置一个header
如果覆盖模式,则替换之前的值,否则加入到值列表中 如果给定值为 null,则删除这个头信息 |
Request |
Request.method(Method method)
设置请求方法
|
static Request |
Request.of(String url)
构建一个HTTP请求
对于传入的URL,可以自定义是否解码已经编码的内容,设置见 HttpGlobalConfig.setDecodeUrl(boolean)在构建Http请求时,用户传入的URL可能有编码后和未编码的内容混合在一起,如果 HttpGlobalConfig.isDecodeUrl()为true,则会统一解码编码后的参数,按照RFC3986规范,在发送请求时,全部编码之。 |
static Request |
Request.of(String url,
Charset charset)
构建一个HTTP请求
对于传入的URL,可以自定义是否解码已经编码的内容。 |
static Request |
Request.of(UrlBuilder url)
构建一个HTTP请求
|
Request |
Request.setMaxRedirectCount(int maxRedirectCount)
设置最大重定向次数
如果次数小于1则表示不重定向,大于等于1表示打开重定向 |
Request |
Request.url(UrlBuilder url)
设置URL
|
| 限定符和类型 | 方法和说明 |
|---|---|
Response |
ClientEngine.send(Request message)
发送HTTP请求
|
| 限定符和类型 | 方法和说明 |
|---|---|
Response |
HttpClient4Engine.send(Request message) |
| 限定符和类型 | 方法和说明 |
|---|---|
Response |
HttpClient5Engine.send(Request message) |
| 限定符和类型 | 方法和说明 |
|---|---|
Response |
JdkClientEngine.send(Request message) |
JdkHttpResponse |
JdkClientEngine.send(Request message,
boolean isAsync)
发送请求
|
| 限定符和类型 | 方法和说明 |
|---|---|
Response |
OkHttpEngine.send(Request message) |
Copyright © 2023. All rights reserved.