Search in sources :

Example 1 with HttpRequest

use of cn.hutool.http.HttpRequest in project hutool by looly.

the class HttpRequestTest method getWithParamsTest.

@Test
@Ignore
public void getWithParamsTest() {
    String url = "http://gc.ditu.aliyun.com/geocoding?ccc=你好";
    HttpRequest request = HttpRequest.get(url).setEncodeUrl(true).body("a=乌海");
    String body = request.execute().body();
    Console.log(body);
// String body2 = HttpUtil.get(url);
// Console.log(body2);
}
Also used : HttpRequest(cn.hutool.http.HttpRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with HttpRequest

use of cn.hutool.http.HttpRequest in project hutool by looly.

the class HttpRequestTest method uploadTest.

@Test
@Ignore
public void uploadTest() {
    File file = FileUtil.file("D:\\face.jpg");
    // 方法一:自定义构建表单
    HttpRequest request = // 
    HttpRequest.post(// 
    "http://localhost:8080/file/upload").form("file", // 
    file).form("fileType", "图片");
    HttpResponse response = request.execute();
    System.out.println(response.body());
}
Also used : HttpRequest(cn.hutool.http.HttpRequest) HttpResponse(cn.hutool.http.HttpResponse) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with HttpRequest

use of cn.hutool.http.HttpRequest in project hutool by looly.

the class HttpRequestTest method customGetTest.

@Test
@Ignore
public void customGetTest() {
    // 自定义构建HTTP GET请求,发送Http GET请求,针对HTTPS安全加密,可以自定义SSL
    HttpRequest request = HttpRequest.get(url).charset(CharsetUtil.CHARSET_GBK).disableCache().setSSLProtocol(SSLSocketFactoryBuilder.TLSv12);
    Console.log(request.execute().body());
}
Also used : HttpRequest(cn.hutool.http.HttpRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with HttpRequest

use of cn.hutool.http.HttpRequest in project hutool by looly.

the class RestTest method postTest2.

@Test
@Ignore
public void postTest2() {
    HttpRequest request = HttpRequest.post("http://211.162.39.204:8181/jeesite-simple/a/open/bizGwbnService/test").body(JSONUtil.createObj().put("aaa", "aaaValue").put("键2", "值2"));
    Console.log(request.execute().body());
}
Also used : HttpRequest(cn.hutool.http.HttpRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with HttpRequest

use of cn.hutool.http.HttpRequest in project hutool by looly.

the class RestTest method postTest.

@Test
@Ignore
public void postTest() {
    HttpRequest request = HttpRequest.post("http://localhost:8090/rest/restTest/").body(JSONUtil.createObj().put("aaa", "aaaValue").put("键2", "值2"));
    Console.log(request.execute().body());
}
Also used : HttpRequest(cn.hutool.http.HttpRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

HttpRequest (cn.hutool.http.HttpRequest)21 Test (org.junit.Test)9 JSONObject (com.alibaba.fastjson.JSONObject)6 Ignore (org.junit.Ignore)5 HttpResponse (cn.hutool.http.HttpResponse)4 JpomRuntimeException (io.jpom.system.JpomRuntimeException)4 File (java.io.File)3 IOException (java.io.IOException)3 JsonMessage (cn.jiangzeyin.common.JsonMessage)2 JSONArray (com.alibaba.fastjson.JSONArray)2 Convert (cn.hutool.core.convert.Convert)1 FileUtil (cn.hutool.core.io.FileUtil)1 Tuple (cn.hutool.core.lang.Tuple)1 Validator (cn.hutool.core.lang.Validator)1 StrUtil (cn.hutool.core.util.StrUtil)1 URLUtil (cn.hutool.core.util.URLUtil)1 Entity (cn.hutool.db.Entity)1 Page (cn.hutool.db.Page)1 ServletUtil (cn.hutool.extra.servlet.ServletUtil)1 HttpUtil (cn.hutool.http.HttpUtil)1