From 5737d1128437b255bc5a68e764d443c2c1ce5b29 Mon Sep 17 00:00:00 2001 From: c0ny1 <1627639645@qq.com> Date: Thu, 19 Dec 2019 22:42:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E7=A8=B3=E5=AE=9A=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E6=9E=90request=20header=E7=9A=84=E9=94=AE=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/utils/HttpClient.java | 9 +++++---- src/main/java/utils/Util.java | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/java/utils/HttpClient.java b/src/main/java/utils/HttpClient.java index 390c356..30d3cd9 100644 --- a/src/main/java/utils/HttpClient.java +++ b/src/main/java/utils/HttpClient.java @@ -8,6 +8,8 @@ import burp.IHttpRequestResponse; import burp.IRequestInfo; import entity.HttpService; + +import java.io.BufferedOutputStream; import java.util.HashMap; import java.util.Map; @@ -111,12 +113,11 @@ private void parserRequest(){ continue; } - if (header.indexOf(": ") > 0) { - String key = header.split(": ")[0]; - String value = header.split(": ")[1]; + if (header.indexOf(":") > 0) { + String key = header.substring(0, header.indexOf(":")); + String value = Util.trimStart(header.substring(header.indexOf(":")+1, header.length())); this.headers.put(key, value); } - System.out.println(header); } if (this.method.equals("POST")) { diff --git a/src/main/java/utils/Util.java b/src/main/java/utils/Util.java index ca30b78..55f49c7 100644 --- a/src/main/java/utils/Util.java +++ b/src/main/java/utils/Util.java @@ -303,6 +303,28 @@ public static String matchByRegular(String str,String reg,int n){ return res; } + /** + * 将字符串开头空格去掉 + * @param str + * @return + */ + public static String trimStart(String str) { + if (str == "" || str == null) { + return str; + } - + final char[] value = str.toCharArray(); + int start = 0, last = 0 + str.length() - 1; + int end = last; + while ((start <= end) && (value[start] <= ' ')) { + start++; + } + if (start == 0 && end == last) { + return str; + } + if (start >= end) { + return ""; + } + return str.substring(start, end); + } }