-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
159 lines (127 loc) · 3.91 KB
/
test.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
var http = require('http');
var request = require("request");
var Iconv = require('iconv').Iconv;
var iconv = new Iconv('EUC-KR', 'UTF-8//TRANSLIT//IGNORE');
var options = {
url: 'https://khuis.khu.ac.kr/java/servlet/khu.cosy.login.loginCheckAction',
port: 80,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body:"user_id=2013104056&password=KIMho0715@#&RequestData="
};
var req = request(options);
var cookie = {};
function setCookie(cookies) {
for (var i in cookies) {
var c = cookies[i];
var tokens = c.split(";");
for (var j in tokens) {
var t = tokens[j].trim();
var tt = t.split("=");
cookie[tt[0]] = tt[1];
}
}
}
function getCookie() {
var str = "";
for (var i in cookie) {
str += i + "=" + cookie[i] + "; ";
}
return str;
}
function getCookieConsole(){
var str = "";
for (var i in cookie) {
str += i + "=" + cookie[i] + "; " + '\n';
}
console.log(str);
}
req.on('response', function(res) {
res.setEncoding('utf8');
res.on('end', function () {
setCookie(res.headers["set-cookie"]);
console.log("cookie1 : "+ getCookie());
options = {
url: 'https://khuis.khu.ac.kr/java/servlet/controllerCosy?' +
'action=17&WID=hsip1004&Pkg=JSP&URL=' +
'JSP./jsp/hssu/infospace/SugangSearchPrintList.jsp[(QUES)]auto=off',
port: 80,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie' : getCookie()
}
};
var req2 = request(options);
req2.on('response', function (res) {
res.setEncoding('utf8');
res.on('end',function () {
console.log("cookie2 : " + JSON.stringify(res.headers));
setCookie(res.headers["set-cookie"]);
options = {
url: 'https://khuis.khu.ac.kr/java/servlet/controllerHssu',
port: 80,
method: 'POST',
headers: {
'Host' : "khuis.khu.ac.kr",
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie' : getCookie()
},
body:"action=655&auto=on&lectYear=2017&lectTerm=20"
};
var req3 = request(options);
req3.on('response', function (res) {
var output = "";
res.setEncoding('utf8');
res.on('data', function (chunk) {
output += chunk;
});
res.on('end', function () {
setCookie(res.headers["set-cookie"]);
console.log("cookie3first : " + JSON.stringify(res.headers));
console.log("output : " + output);
console.log("cookie3 : ");
getCookieConsole();
});
});
});
})
});
}).on('error', function(err) {
console.log(err);
});
//
//
//
//
//
// var options = {
// url: 'https://khuis.khu.ac.kr/java/servlet/khu.cosy.login.loginCheckAction',
// port: 80,
// method: 'POST',
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded'
// },
// encoding: null,
// body:"user_id=2013104056&password=KIMho0715!@&RequestData="
// };
//
// var req = request(options);
// req.on('response', function (res) {
// var output = new Buffer([]);
//
// res.on('data', function (chunk) {
// output = Buffer.concat([output, chunk]);
// });
//
// res.on('end', function () {
//
//
// console.log(iconv.convert(output).toString());
// console.log(res.headers);
// });
//
//
// });