Compare commits
2 Commits
21045b6e1a
...
1ddf14060e
Author | SHA1 | Date |
---|---|---|
octopusYan | 1ddf14060e | |
octopusYan | bddc0ea80d |
|
@ -10,7 +10,7 @@ import javafx.stage.Stage;
|
|||
import javafx.stage.StageStyle;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import top.octopusyan.base.BaseController;
|
||||
import top.octopusyan.controller.LoginController;
|
||||
import top.octopusyan.http.OkHttpClientConfig;
|
||||
import top.octopusyan.manager.FrpManager;
|
||||
import top.octopusyan.manager.http.HttpConfig;
|
||||
|
@ -21,6 +21,8 @@ import top.octopusyan.utils.AlertUtil;
|
|||
import top.octopusyan.utils.EncryptionUtil;
|
||||
import top.octopusyan.utils.FxmlUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author : octopus yan
|
||||
* @email : octopus_yan@foxmail.com
|
||||
|
@ -84,11 +86,11 @@ public class YanFrpApplication extends Application {
|
|||
root.getPrefHeight() + 20,
|
||||
Color.TRANSPARENT
|
||||
);
|
||||
scene.getStylesheets().addAll(getClass().getResource("/css/root.css").toExternalForm());
|
||||
scene.getStylesheets().addAll(Objects.requireNonNull(getClass().getResource("/css/root.css")).toExternalForm());
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
|
||||
BaseController controller = fxmlLoader.getController();
|
||||
LoginController controller = fxmlLoader.getController();
|
||||
controller.setApplication(this);
|
||||
|
||||
} catch (Throwable t) {
|
||||
|
|
|
@ -32,29 +32,27 @@ public class OkHttpClientConfig {
|
|||
public static final HashMap<String, List<Cookie>> cookieStore = new HashMap<>();
|
||||
|
||||
public static OkHttpClient httpClient() {
|
||||
Interceptor tokenInterceptor = new Interceptor() {//全局拦截器,往请求头部添加 token 字段,实现全局添加 token
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {// 打印请求报文
|
||||
// 获取请求
|
||||
Request request = chain.request();
|
||||
// 取出请求参数
|
||||
String reqBody = getRequestBody(request);
|
||||
//全局拦截器,往请求头部添加 token 字段,实现全局添加 token
|
||||
Interceptor tokenInterceptor = chain -> {// 打印请求报文
|
||||
// 获取请求
|
||||
Request request = chain.request();
|
||||
// 取出请求参数
|
||||
String reqBody = getRequestBody(request);
|
||||
|
||||
// 打印请求报文
|
||||
log.info("【" + TAG + "】 " + String.format("发送新请求\n-\tmethod:%s\n-\turl:%s\n-\theaders: %s\n-\tbody:%s",
|
||||
request.method(), request.url(), request.headers(), reqBody));
|
||||
// 执行请求,获取响应报文
|
||||
Response response = chain.proceed(request);
|
||||
// 获取响应内容 TODO 读取结果乱码
|
||||
String respBody = getResponseBody(response);
|
||||
// 打印响应报文
|
||||
// 打印请求报文
|
||||
log.info("【" + TAG + "】 " + String.format("发送新请求\n-\tmethod:%s\n-\turl:%s\n-\theaders: %s\n-\tbody:%s",
|
||||
request.method(), request.url(), request.headers(), reqBody));
|
||||
// 执行请求,获取响应报文
|
||||
Response response = chain.proceed(request);
|
||||
// 获取响应内容 TODO 读取结果乱码
|
||||
String respBody = getResponseBody(response);
|
||||
// 打印响应报文
|
||||
// log.info("【" + TAG + "】 " + String.format("收到响应 %s %s\n-\t请求url:%s\n-\t请求body:%s\n-\t响应body:%s",
|
||||
// response.code(), response.message(), response.request().url(), reqBody, respBody));
|
||||
log.info("【" + TAG + "】 " + String.format("收到响应 %s %s\n-\t请求url:%s\n-\t请求body:%s",
|
||||
response.code(), response.message(), response.request().url(), reqBody));
|
||||
log.info("【" + TAG + "】 " + String.format("收到响应 %s %s\n-\t请求url:%s\n-\t请求body:%s",
|
||||
response.code(), response.message(), response.request().url(), reqBody));
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
};
|
||||
|
||||
Dispatcher dispatcher = new Dispatcher();
|
||||
|
@ -93,6 +91,7 @@ public class OkHttpClientConfig {
|
|||
if (contentType != null) {
|
||||
charset = contentType.charset(StandardCharsets.UTF_8);
|
||||
}
|
||||
assert charset != null;
|
||||
reqBody = buffer.readString(charset);
|
||||
}
|
||||
|
||||
|
@ -116,6 +115,7 @@ public class OkHttpClientConfig {
|
|||
charset = contentType.charset(charset);
|
||||
|
||||
//获取Response的body的字符串 并打印
|
||||
assert charset != null;
|
||||
respBody = buffer.clone().readString(charset);
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class OkHttpClientConfig {
|
|||
@Override
|
||||
public List<Cookie> loadForRequest(@NotNull HttpUrl httpUrl) {
|
||||
List<Cookie> cookies = cookieStore.get(httpUrl.host());
|
||||
return cookies != null ? cookies : new ArrayList<Cookie>();
|
||||
return cookies != null ? cookies : new ArrayList<>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue