Package | Description |
---|---|
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/ |
Modifier and Type | Method and Description |
---|---|
static Request |
HttpUtil.createGet(String url)
创建Http GET请求对象
|
static Request |
HttpUtil.createPost(String url)
创建Http POST请求对象
|
static Request |
HttpUtil.createRequest(String url,
Method method)
创建Http请求对象
|
Modifier and Type | Method and Description |
---|---|
static Response |
HttpUtil.send(Request request)
使用默认HTTP引擎,发送HTTP请求
|
static String |
HttpUtil.toString(Request request)
打印
Request 为可读形式 |
Modifier and Type | Method and Description |
---|---|
Request |
Request.basicAuth(String username,
String password)
简单验证,生成的头信息类似于:
Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
Request |
Request.body(HttpBody body)
添加请求体
|
Request |
Request.body(String body)
添加字符串请求体
|
Request |
Request.charset(Charset charset)
设置自定义编码,一般用于:
编码请求体
服务端未返回编码时,使用此编码解码响应体
|
Request |
Request.form(Map<String,Object> formMap)
添加请求表单内容
|
Request |
RequestContext.getRequest()
获取请求
|
Request |
Request.header(String name,
String value,
boolean isOverride)
设置一个header
如果覆盖模式,则替换之前的值,否则加入到值列表中 如果给定值为 null ,则删除这个头信息 |
Request |
Request.locationTo(String location)
更新设置重定向后的URL,用于处理相对路径
注意此方法会修改对象本身 |
Request |
Request.method(Method method)
设置请求方法
|
static Request |
Request.of(String url)
构建一个HTTP请求,默认编解码规则,规则为:
如果传入的URL已编码,则先解码,再按照RFC3986规范重新编码。
|
static Request |
Request.of(String url,
Charset decodeAndEncodeCharset)
构建一个HTTP请求
对于传入的URL,可以自定义是否解码已经编码的内容,规则如下: 如果url已编码,则decodeAndEncodeCharset设置为 null ,此时URL不会解码,发送也不编码。 |
static Request |
Request.of(UrlBuilder url)
构建一个HTTP请求
|
static Request |
Request.ofWithoutEncode(String url)
构建一个HTTP请求,不解码和编码,此时要求用户传入的URL必须是已经编码过的。
|
Request |
Request.setEncodeUrl(boolean isEncodeUrl)
设置是否编码URL
|
Request |
Request.setMaxRedirects(int maxRedirects)
设置最大重定向次数
如果次数小于1则表示不重定向,大于等于1表示打开重定向 |
Request |
Request.setRest(boolean isRest)
设置是否rest模式
rest模式下get请求不会把参数附加到URL之后,而是作为body发送 |
Request |
Request.url(UrlBuilder url)
设置URL
|
Modifier and Type | Method and Description |
---|---|
RequestContext |
RequestContext.setRequest(Request request)
设置请求,在重新请求或重定向时,更新请求信息
|
Constructor and Description |
---|
RequestContext(Request request)
构造
|
Modifier and Type | Method and Description |
---|---|
T |
EngineRequestBuilder.build(Request message)
构建引擎请求对象
|
Response |
ClientEngine.send(Request message)
发送HTTP请求
|
Modifier and Type | Method and Description |
---|---|
org.apache.http.client.methods.HttpUriRequest |
HttpUriRequestBuilder.build(Request message) |
Response |
HttpClient4Engine.send(Request message) |
Constructor and Description |
---|
HttpClient4Response(org.apache.http.HttpResponse rawRes,
Request message)
构造
通过传入一个请求时的编码,当无法获取响应内容的编码时,默认使用响应时的编码 |
Modifier and Type | Method and Description |
---|---|
org.apache.hc.core5.http.ClassicHttpRequest |
ClassicHttpRequestBuilder.build(Request message) |
Response |
HttpClient5Engine.send(Request message) |
Constructor and Description |
---|
HttpClient5Response(org.apache.hc.core5.http.ClassicHttpResponse rawRes,
Request message)
构造
通过传入一个请求时的编码,当无法获取响应内容的编码时,默认使用响应时的编码 |
Modifier and Type | Method and Description |
---|---|
JdkHttpConnection |
JdkRequestBuilder.build(Request message) |
JdkHttpResponse |
JdkClientEngine.send(Request message) |
Constructor and Description |
---|
JdkHttpResponse(JdkHttpConnection httpConnection,
JdkCookieManager cookieManager,
Request message)
构造
|
Modifier and Type | Method and Description |
---|---|
okhttp3.Request |
OkHttpRequestBuilder.build(Request message) |
Response |
OkHttpEngine.send(Request message) |
Constructor and Description |
---|
OkHttpResponse(okhttp3.Response rawRes,
Request message) |
Copyright © 2025. All rights reserved.