权限的树状结构
parent
523ec042c5
commit
054a15a6f0
@ -1,70 +1,70 @@
|
|||||||
package com.shxy.xymanager_common.util.http;
|
//package com.shxy.xymanager_common.util.http;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
//import com.alibaba.fastjson.JSONObject;
|
||||||
import io.github.admin4j.http.HttpRequest;
|
//import io.github.admin4j.http.HttpRequest;
|
||||||
import io.github.admin4j.http.core.Pair;
|
//import io.github.admin4j.http.core.Pair;
|
||||||
import io.github.admin4j.http.util.HttpUtil;
|
//import io.github.admin4j.http.util.HttpUtil;
|
||||||
import okhttp3.Response;
|
//import okhttp3.Response;
|
||||||
|
//
|
||||||
import java.io.File;
|
//import java.io.File;
|
||||||
import java.io.IOException;
|
//import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
//import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
//import java.util.HashMap;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
import java.util.Map;
|
//import java.util.Map;
|
||||||
|
//
|
||||||
public class OkHttpUtils {
|
//public class OkHttpUtils {
|
||||||
|
//
|
||||||
public static JSONObject get(String url, Map<String, Object> queryParams) throws IOException {
|
// public static JSONObject get(String url, Map<String, Object> queryParams) throws IOException {
|
||||||
Response response = HttpUtil.get(url, queryParams);
|
// Response response = HttpUtil.get(url, queryParams);
|
||||||
return JSONObject.parseObject(response.body().string());
|
// return JSONObject.parseObject(response.body().string());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public static JSONObject get(String url, Map<String, Object> queryParams, Map<String, Object> headers) throws IOException {
|
// public static JSONObject get(String url, Map<String, Object> queryParams, Map<String, Object> headers) throws IOException {
|
||||||
HttpRequest httpRequest = HttpRequest.get(url);
|
// HttpRequest httpRequest = HttpRequest.get(url);
|
||||||
setParams(queryParams, httpRequest);
|
// setParams(queryParams, httpRequest);
|
||||||
Response response = httpRequest.queryParams().headers(headers).execute();
|
// Response response = httpRequest.queryParams().headers(headers).execute();
|
||||||
return JSONObject.parseObject(response.body().string());
|
// return JSONObject.parseObject(response.body().string());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public static JSONObject post(String url, String json) throws IOException {
|
// public static JSONObject post(String url, String json) throws IOException {
|
||||||
Response response = HttpUtil.post(url, json);
|
// Response response = HttpUtil.post(url, json);
|
||||||
assert response.body() != null;
|
// assert response.body() != null;
|
||||||
return JSONObject.parseObject(response.body().string());
|
// return JSONObject.parseObject(response.body().string());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public static JSONObject postForm(String url, Map<String, Object> formParams) throws IOException {
|
// public static JSONObject postForm(String url, Map<String, Object> formParams) throws IOException {
|
||||||
Response response = HttpUtil.postForm(url, formParams);
|
// Response response = HttpUtil.postForm(url, formParams);
|
||||||
assert response.body() != null;
|
// assert response.body() != null;
|
||||||
return JSONObject.parseObject(response.body().string());
|
// return JSONObject.parseObject(response.body().string());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public static JSONObject post(String url, String json, Map<String, Object> headers) throws IOException {
|
// public static JSONObject post(String url, String json, Map<String, Object> headers) throws IOException {
|
||||||
HttpRequest httpRequest = HttpRequest.post(url);
|
// HttpRequest httpRequest = HttpRequest.post(url);
|
||||||
httpRequest.setBody(json);
|
// httpRequest.setBody(json);
|
||||||
Response response = httpRequest.headers(headers).execute();
|
// Response response = httpRequest.headers(headers).execute();
|
||||||
return JSONObject.parseObject(response.body().string());
|
// return JSONObject.parseObject(response.body().string());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private static void setParams(Map<String, Object> queryParams, HttpRequest httpRequest) {
|
// private static void setParams(Map<String, Object> queryParams, HttpRequest httpRequest) {
|
||||||
List<Pair> pairs = new ArrayList<>(queryParams.size());
|
// List<Pair> pairs = new ArrayList<>(queryParams.size());
|
||||||
queryParams.forEach((x, y) -> pairs.add(Pair.of(x, y)));
|
// queryParams.forEach((x, y) -> pairs.add(Pair.of(x, y)));
|
||||||
if (pairs.size() > 0) {
|
// if (pairs.size() > 0) {
|
||||||
pairs.forEach(httpRequest::queryParams);
|
// pairs.forEach(httpRequest::queryParams);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private static JSONObject upload() throws IOException {
|
// private static JSONObject upload() throws IOException {
|
||||||
File file = new File("C:\\Users\\andanyang\\Downloads\\Sql.txt");
|
// File file = new File("C:\\Users\\andanyang\\Downloads\\Sql.txt");
|
||||||
Map<String, Object> formParams = new HashMap<>();
|
// Map<String, Object> formParams = new HashMap<>();
|
||||||
formParams.put("key", "test");
|
// formParams.put("key", "test");
|
||||||
formParams.put("file", file);
|
// formParams.put("file", file);
|
||||||
formParams.put("token", "WXyUseb-D4sCum-EvTIDYL-mEehwDtrSBg-Zca7t:qgOcR2gUoKmxt-VnsNb657Oatzo=:eyJzY29wZSI6InpoYW56aGkiLCJkZWFkbGluZSI6MTY2NTMwNzUxNH0=");
|
// formParams.put("token", "WXyUseb-D4sCum-EvTIDYL-mEehwDtrSBg-Zca7t:qgOcR2gUoKmxt-VnsNb657Oatzo=:eyJzY29wZSI6InpoYW56aGkiLCJkZWFkbGluZSI6MTY2NTMwNzUxNH0=");
|
||||||
Response response = HttpUtil.upload("https://upload.qiniup.com/", formParams);
|
// Response response = HttpUtil.upload("https://upload.qiniup.com/", formParams);
|
||||||
return JSONObject.parseObject(response.body().string());
|
// return JSONObject.parseObject(response.body().string());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private static void download() throws IOException {
|
// private static void download() throws IOException {
|
||||||
HttpUtil.down("https://gitee.com/admin4j/common-http","path/");
|
// HttpUtil.down("https://gitee.com/admin4j/common-http","path/");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
Loading…
Reference in New Issue