mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add http engine
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.http.meta.ContentType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.StreamProgress;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.client.engine.jdk.HttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@@ -7,6 +7,10 @@ import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.net.ssl.SSLProtocols;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.http.client.engine.jdk.HttpRequest;
|
||||
import cn.hutool.http.client.engine.jdk.HttpResponse;
|
||||
import cn.hutool.http.meta.Header;
|
||||
import cn.hutool.http.meta.Method;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -213,7 +217,7 @@ public class HttpRequestTest {
|
||||
urlBuilder.setScheme("https").setHost("hutool.cn");
|
||||
|
||||
final HttpRequest httpRequest = new HttpRequest(urlBuilder);
|
||||
httpRequest.setMethod(Method.GET).execute();
|
||||
httpRequest.method(Method.GET).execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -5,6 +5,9 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.http.client.engine.jdk.HttpRequest;
|
||||
import cn.hutool.http.meta.Header;
|
||||
import cn.hutool.http.meta.Method;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@@ -3,6 +3,8 @@ package cn.hutool.http;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.http.client.engine.jdk.HttpRequest;
|
||||
import cn.hutool.http.client.engine.jdk.HttpResponse;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.client.engine.jdk.HttpResponse;
|
||||
import cn.hutool.http.meta.Header;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.http.client.engine.jdk.HttpRequest;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.client.engine.jdk.HttpResponse;
|
||||
import cn.hutool.http.meta.Header;
|
||||
import org.brotli.dec.BrotliInputStream;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.client.engine.jdk.HttpRequest;
|
||||
import cn.hutool.http.meta.Header;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
@@ -20,7 +22,7 @@ public class RestTest {
|
||||
.body(JSONUtil.ofObj()
|
||||
.set("aaa", "aaaValue")
|
||||
.set("键2", "值2").toString());
|
||||
Assert.assertEquals("application/json;charset=UTF-8", request.header("Content-Type"));
|
||||
Assert.assertEquals("application/json;charset=UTF-8", request.header(Header.CONTENT_TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -2,6 +2,9 @@ package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.client.engine.jdk.HttpRequest;
|
||||
import cn.hutool.http.client.engine.jdk.HttpResponse;
|
||||
import cn.hutool.http.meta.Header;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@@ -2,7 +2,8 @@ package cn.hutool.http.body;
|
||||
|
||||
import cn.hutool.core.io.resource.StringResource;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.http.HttpResource;
|
||||
import cn.hutool.core.io.resource.HttpResource;
|
||||
import cn.hutool.http.client.body.MultipartBody;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
23
hutool-http/src/test/java/cn/hutool/http/client/HttpClient4EngineTest.java
Executable file
23
hutool-http/src/test/java/cn/hutool/http/client/HttpClient4EngineTest.java
Executable file
@@ -0,0 +1,23 @@
|
||||
package cn.hutool.http.client;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.meta.Method;
|
||||
import cn.hutool.http.client.engine.httpclient4.HttpClient4Engine;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpClient4EngineTest {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test
|
||||
@Ignore
|
||||
public void getTest() {
|
||||
final ClientEngine engine = new HttpClient4Engine();
|
||||
|
||||
final Request req = Request.of("https://www.hutool.cn/").method(Method.GET);
|
||||
final Response res = engine.send(req);
|
||||
|
||||
Console.log(res.getStatus());
|
||||
Console.log(res.body());
|
||||
}
|
||||
}
|
23
hutool-http/src/test/java/cn/hutool/http/client/HttpClient5EngineTest.java
Executable file
23
hutool-http/src/test/java/cn/hutool/http/client/HttpClient5EngineTest.java
Executable file
@@ -0,0 +1,23 @@
|
||||
package cn.hutool.http.client;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.meta.Method;
|
||||
import cn.hutool.http.client.engine.httpclient5.HttpClient5Engine;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpClient5EngineTest {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test
|
||||
@Ignore
|
||||
public void getTest() {
|
||||
final ClientEngine engine = new HttpClient5Engine();
|
||||
|
||||
final Request req = Request.of("https://www.hutool.cn/").method(Method.GET);
|
||||
final Response res = engine.send(req);
|
||||
|
||||
Console.log(res.getStatus());
|
||||
Console.log(res.body());
|
||||
}
|
||||
}
|
23
hutool-http/src/test/java/cn/hutool/http/client/OkHttpEngineTest.java
Executable file
23
hutool-http/src/test/java/cn/hutool/http/client/OkHttpEngineTest.java
Executable file
@@ -0,0 +1,23 @@
|
||||
package cn.hutool.http.client;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.http.client.engine.okhttp.OkHttpEngine;
|
||||
import cn.hutool.http.meta.Method;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OkHttpEngineTest {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test
|
||||
@Ignore
|
||||
public void getTest(){
|
||||
final ClientEngine engine = new OkHttpEngine();
|
||||
|
||||
final Request req = Request.of("https://www.hutool.cn/").method(Method.GET);
|
||||
final Response res = engine.send(req);
|
||||
|
||||
Console.log(res.getStatus());
|
||||
Console.log(res.body());
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.http.server;
|
||||
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.http.meta.ContentType;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
|
||||
public class BlankServerTest {
|
||||
|
@@ -4,8 +4,8 @@ import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.net.multipart.UploadFile;
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.meta.ContentType;
|
||||
import cn.hutool.http.meta.Header;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
|
Reference in New Issue
Block a user