-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyRequest.java
More file actions
73 lines (63 loc) · 1.71 KB
/
Copy pathMyRequest.java
File metadata and controls
73 lines (63 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package tomcatdome;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
public class MyRequest {
private String url;
private String method;
private Map<String, String> paramMap;
public MyRequest(InputStream inputStream) throws IOException {
StringBuilder httpRequeset = new StringBuilder();
byte[] httpRequestByte = new byte[1024];
int length = 0;
if ((length = inputStream.read(httpRequestByte)) > 0) {
httpRequeset.append(new String(httpRequestByte, 0, length));
}
System.out.println("httpRequeset = { " + httpRequeset + " } ");
if (httpRequeset.length() <= 0) {
return;
}
String httpHead = httpRequeset.toString().split("\n")[0];
String urlAndParms = httpHead.split("\\s")[1];
String[] urlAndParmsArray = urlAndParms.split("\\?");
url = urlAndParmsArray[0];
if (urlAndParmsArray.length > 1) {
String[] params = urlAndParmsArray[1].split("\\&");
for (String param : params) {
if (paramMap == null) {
paramMap = new HashMap<>();
}
paramMap.put(param.split("\\=")[0], param.split("\\=")[1]);
}
}
method = httpHead.split("\\s")[0];
System.out.println(" MyRequest = { " + this + " } ");
}
public String getUrl() {
return url;
}
public void seturl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public Map<String, String> getParamMap() {
return paramMap;
}
public void setParamMap(Map<String, String> paramMap) {
this.paramMap = paramMap;
}
@Override
public String toString() {
return "MyRequest{" +
"url='" + url + '\'' +
", method='" + method + '\'' +
", paramMap=" + paramMap +
'}';
}
}