Releases: gudaoxuri/dew-common
Releases · gudaoxuri/dew-common
2.0.0
1.3.0
Support http operations
Http操作($.http)
// get
String result = $.http.get("https://httpbin.org/get");
// get 带 head
result = $.http.get("https://httpbin.org/get", new HashMap<String, String>() {{
put("Customer-A", "AAA");
put("Accept", "json");
}});
// get 包含 head、Content-Type、编码、超时等信息
result = $.http.get("https://httpbin.org/get", new HashMap<String, String>() {{
put("Customer-A", "AAA");
put("Accept", "json");
}}, "application/json; charset=utf-8", "utf-8", 5000);
// delete
result = $.http.delete("https://httpbin.org/delete");
Assert.assertEquals("httpbin.org", $.json.toJson(result).get("headers").get("Host").asText());
// post - data
result = $.http.post("https://httpbin.org/post", "some data");
// post - form
result = $.http.post("https://httpbin.org/post", new HashMap<String, Object>() {{
put("a", "1");
}}, "application/x-www-form-urlencoded");
// post - file
result = $.http.post("https://httpbin.org/post", new File(this.getClass().getResource("/").getPath() + "conf1.json"));
// put - data
result = $.http.put("https://httpbin.org/put", "some data");
// put - form
result = $.http.put("https://httpbin.org/put", new HashMap<String, Object>() {{
put("a", "1");
}}, "application/x-www-form-urlencoded");
// put - file
result = $.http.put("https://httpbin.org/put", new File(this.getClass().getResource("/").getPath() + "conf1.json"));
// put 返回带 head的内容,同样还有getWithHead、postWithHead、deleteWtihHead
HttpHelper.WrapHead wrapHead = $.http.putWithHead("https://httpbin.org/put", new File(this.getClass().getResource("/").getPath() + "conf1.json"));
// head
Map<String, String> head = $.http.head("https://httpbin.org/get");
// options
head = $.http.options("https://httpbin.org/get");