Skip to content

Commit

Permalink
Merge pull request #20 from podm1n/patch-1
Browse files Browse the repository at this point in the history
fixed a bug about the handle of GET request
  • Loading branch information
c0ny1 authored Jul 28, 2021
2 parents 6c4d9f1 + b14916f commit 51e7988
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions src/main/java/burp/HttpAndHttpsProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,50 @@ public static Map<String,String> HttpProxy(String url,List<String> headers,byte[
//BurpExtender.stdout.println("value: " + h[1].trim());
httpConn.setRequestProperty(header_key, header_value);
}
//设置控制请求方法的Flag
String methodFlag = "";
// 设置通用的请求属性
for(String header:headers){
if(header.startsWith("GET") ||
header.startsWith("POST") ||
header.startsWith("PUT")){
if(header.startsWith("GET")){
methodFlag = "GET";
}
else if(header.startsWith("POST")||
header.startsWith("PUT")){
methodFlag = "POST";
}//在循环中重复设置了methodFlag,代码非常的丑陋冗余,请见谅
continue;
}//判断结束后以键值对的方式获取header
String[] h = header.split(":");
String header_key = h[0].trim();
String header_value = h[1].trim();
httpsConn.setRequestProperty(header_key, header_value);
}

// 发送POST请求必须设置如下两行
httpConn.setDoOutput(true);
httpConn.setDoInput(true);


// 获取URLConnection对象对应的输出流
out = new PrintWriter(httpConn.getOutputStream());
if (methodFlag.equals("GET")){
// 发送GET请求必须设置如下两行
httpsConn.setDoOutput(false);
httpsConn.setDoInput(true);

if(body != null) {
// 发送请求参数
out.print(new String(body));
// 获取URLConnection对象的连接
httpsConn.connect();
}
else if(methodFlag.equals("POST")){
// 发送POST请求必须设置如下两行
httpsConn.setDoOutput(true);
httpsConn.setDoInput(true);

// 获取URLConnection对象对应的输出流
out = new PrintWriter(httpsConn.getOutputStream());
if(body != null) {
// 发送请求参数
out.print(new String(body));
}
// flush输出流的缓冲
out.flush();
}
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
String line;
Expand Down Expand Up @@ -327,4 +356,4 @@ public boolean verify(String hostname, SSLSession session) {
return true;
}
}
}
}

0 comments on commit 51e7988

Please sign in to comment.