Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

更新添加任意请求头功能,解决部分场景需要cookie或者token登录的情况 #38

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/main/java/com/drops/ui/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public class MainController {
// 设置超时
@FXML
private TextField httpTimeout;
//设置请求头 cookie
@FXML
private TextField globalHeader;
public static HashMap<String, String> myHead = new HashMap();
@FXML
private TextField vps;
@FXML
Expand Down Expand Up @@ -363,6 +367,11 @@ public boolean connect() {

public void check(ActionEvent actionEvent) {
try {
//检测时取请求头
if(!this.globalHeader.getText().equals("")) {
String header[] = this.globalHeader.getText().split(":",2);
this.myHead.put(header[0], header[1].trim());
}
SpringBootInfo info = new SpringBootInfo();
info.doCheck(this.targetAddress.getText());
}catch (Exception e){
Expand Down
46 changes: 23 additions & 23 deletions src/main/java/com/drops/utils/HTTPUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.drops.utils;

import cn.hutool.http.HttpGlobalConfig;
import cn.hutool.http.HttpRequest;
//import cn.hutool.http.ReqHook;
import cn.hutool.http.HttpResponse;
import com.drops.ui.MainController;
import sun.applet.Main;
Expand Down Expand Up @@ -38,9 +38,9 @@ public static HttpResponse deleteRequest(String target, String s) {
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");
HttpResponse result = null;
if (proxy == null){
result = HttpRequest.delete(url).execute();
result = ReqHook.delete(url).execute();
}else {
result = HttpRequest.delete(url).setProxy(proxy).execute();
result = ReqHook.delete(url).setProxy(proxy).execute();
}

return result;
Expand All @@ -64,9 +64,9 @@ public static HttpResponse getRequest(String target){
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");
HttpResponse result = null;
if (proxy == null){
result = HttpRequest.get(url).execute();
result = ReqHook.get(url).execute();
}else {
result = HttpRequest.get(url).setProxy(proxy).execute();
result = ReqHook.get(url).setProxy(proxy).execute();
}

return result;
Expand All @@ -78,9 +78,9 @@ public static HttpResponse getRequest(String target, String point){
HttpResponse result = null;
System.out.println(url);
if (proxy == null){
result = HttpRequest.get(url).execute();
result = ReqHook.get(url).execute();
}else {
result = HttpRequest.get(url).setProxy(proxy).execute();
result = ReqHook.get(url).setProxy(proxy).execute();
}

return result;
Expand All @@ -94,7 +94,7 @@ public static HttpResponse getRequest(String target, String point){
public static HttpResponse getRequestProxy(String target){
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");
String url = URLUtil.normalizeURL(target);
HttpResponse result = HttpRequest.get(target)
HttpResponse result = ReqHook.get(target)
.setProxy(proxy).execute();
return result;
}
Expand All @@ -111,11 +111,11 @@ public static HttpResponse postRequestV1(String target, String Point){
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");
HttpResponse result = null;
if (proxy != null){
result = HttpRequest.post(url)
result = ReqHook.post(url)
.header("Content-Type","application/x-www-form-urlencoded")
.setProxy(proxy).execute();
}else {
result = HttpRequest.post(url)
result = ReqHook.post(url)
.header("Content-Type","application/x-www-form-urlencoded")
.execute();
}
Expand All @@ -127,12 +127,12 @@ public static HttpResponse postRequestV1(String target, String Point, String bob
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");
HttpResponse result = null;
if (proxy != null){
result = HttpRequest.post(url)
result = ReqHook.post(url)
.header("Content-Type","application/x-www-form-urlencoded")
.body(boby)
.setProxy(proxy).execute();
}else {
result = HttpRequest.post(url)
result = ReqHook.post(url)
.body(boby)
.header("Content-Type","application/x-www-form-urlencoded")
.execute();
Expand All @@ -144,7 +144,7 @@ public static HttpResponse postRequestV1(String target, String Point, String bob
public static HttpResponse postRequestV1Proxy(String target, String Point){
String url = URLUtil.normalizeURL(target) + Point;
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");
HttpResponse result = HttpRequest.post(url)
HttpResponse result = ReqHook.post(url)
.header("Content-Type","application/x-www-form-urlencoded")
.setProxy(proxy).execute();
return result;
Expand All @@ -158,13 +158,13 @@ public static HttpResponse H2PostRequest(String target, String boby){

HttpResponse result;
if (proxy != null){
result = HttpRequest.post(target)
result = ReqHook.post(target)
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Referer", target)
.body(boby)
.setProxy(proxy).execute();
}else {
result = HttpRequest.post(target)
result = ReqHook.post(target)
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Referer", target)
.body(boby)
Expand All @@ -181,13 +181,13 @@ public static HttpResponse postRequestjson(String target, String point ,String j

HttpResponse result;
if (proxy != null){
result = HttpRequest.post(url)
result = ReqHook.post(url)
.header("Content-Type", "application/json")
.header("Referer", target)
.body(json)
.setProxy(proxy).execute();
}else {
result = HttpRequest.post(url)
result = ReqHook.post(url)
.header("Content-Type", "application/json")
.header("Referer", target)
.body(json)
Expand All @@ -200,7 +200,7 @@ public static HttpResponse postRequestjson(String target, String point ,String j
public static HttpResponse postRequestV1Proxy(String target, String Point, String boby){
String url = URLUtil.normalizeURL(target) + Point;
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");
HttpResponse result = HttpRequest.post(url)
HttpResponse result = ReqHook.post(url)
.header("Content-Type","application/x-www-form-urlencoded")
.body(boby)
.setProxy(proxy).execute();
Expand All @@ -221,12 +221,12 @@ public static HttpResponse postRequestV2(String target, String Point){
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");
HttpResponse result = null;
if (proxy != null){
result = HttpRequest.post(url)
result = ReqHook.post(url)
.header("Content-Type","application/json")
.header("Cache-Control", "max-age=0")
.setProxy(proxy).execute();
}else {
result = HttpRequest.post(url)
result = ReqHook.post(url)
.header("Cache-Control", "max-age=0")
.header("Content-Type","application/json")
.execute();
Expand All @@ -240,13 +240,13 @@ public static HttpResponse postRequestV2(String target, String Point, String bob
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");
HttpResponse result = null;
if (proxy != null){
result = HttpRequest.post(url)
result = ReqHook.post(url)
.header("Content-Type","application/json")
.header("Cache-Control", "max-age=0")
.body(boby)
.setProxy(proxy).execute();
}else {
result = HttpRequest.post(url)
result = ReqHook.post(url)
.header("Cache-Control", "max-age=0")
.header("Content-Type","application/json")
.body(boby)
Expand All @@ -261,7 +261,7 @@ public static HttpResponse postRequestV2Proxy(String target, String Point){
String url = URLUtil.normalizeURL(target) + Point;
Proxy proxy = (Proxy) MainController.currentProxy.get("proxy");

HttpResponse result = HttpRequest.post(url)
HttpResponse result = ReqHook.post(url)
.header("Content-Type","application/json")
.setProxy(proxy).execute();
return result;
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/drops/utils/ReqHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.drops.utils;

import cn.hutool.http.Method;
import com.drops.ui.MainController;
import cn.hutool.http.HttpRequest;
import com.drops.ui.MainController;

//继承HttpRequest,添加请求头。当前仅修改get,post,delete
public class ReqHook extends HttpRequest {
public ReqHook(String url) {
super(url);
if(!MainController.myHead.isEmpty()) {
this.addHeaders(MainController.myHead);
}
}
public static HttpRequest get(String url) {
return (new ReqHook(url)).method(Method.GET);
}

public static HttpRequest post(String url) {
return (new ReqHook(url)).method(Method.POST);
}

public static HttpRequest delete(String url) {
return (new ReqHook(url)).method(Method.DELETE);
}

}
29 changes: 22 additions & 7 deletions src/main/resources/a.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,31 @@
</font>
</Label>
<TextField fx:id="httpTimeout" layoutX="80.0" layoutY="20.0" prefHeight="23.0" prefWidth="100.0" />

</children>

</HBox>

</content>
</TitledPane>
<TitledPane animated="false" prefHeight="78.0" prefWidth="800.0" text="复杂请求">
<content>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<Label prefHeight="24.0" prefWidth="55.0" text="请求头" textAlignment="JUSTIFY">
<font>
<Font size="14.0" />
</font>
</Label>
<TextField fx:id="globalHeader" prefHeight="25.0" prefWidth="215.0" promptText="Cookie: xxx" />

</children>
</HBox>
</content>
</TitledPane>
<TitledPane animated="false" prefHeight="69.0" prefWidth="900.0" text="服务器配置">
<content>
<HBox prefHeight="0.0" prefWidth="798.0" spacing="4.0">
<HBox prefHeight="72.0" prefWidth="898.0" spacing="4.0">
<children>
<Label text="服务器地址">
<HBox.margin>
Expand All @@ -59,18 +75,18 @@
</Label>
<TextField fx:id="vps" prefHeight="27.0" prefWidth="312.0" />
<Button fx:id="connect" mnemonicParsing="false" onAction="#connect" prefHeight="23.0" prefWidth="84.0" text="连接" />
<Label prefHeight="50.0" prefWidth="50.0" text="HPort" >
<Label prefHeight="50.0" prefWidth="50.0" text="HPort">
<font>
<Font size="16.0" />
</font>
</Label>
<TextField fx:id="hport" prefHeight="40.0" prefWidth="90.0" text="3456"/>
<Label prefHeight="60.0" prefWidth="50.0" text="LPort" >
<TextField fx:id="hport" prefHeight="40.0" prefWidth="90.0" text="3456" />
<Label prefHeight="60.0" prefWidth="50.0" text="LPort">
<font>
<Font size="16.0" />
</font>
</Label>
<TextField fx:id="lport" prefHeight="40.0" prefWidth="90.0" text="1389" />
<TextField fx:id="lport" prefHeight="40.0" prefWidth="90.0" text="1389" />

</children>
</HBox>
Expand Down Expand Up @@ -133,7 +149,6 @@
</Tab>
</tabs>
</TabPane>
<HBox prefHeight="0.0" prefWidth="800.0" />

</children>

Expand Down