我在试着尝试模拟登入学校的校务系统
但查了网络上有关Node.js模拟Post的方法
但却一直抓到登入画面而已,无法抓到登入后的东西
因此想请问各位大大我是否是哪里做错了呢
以下是我的程式码
var http = require("http");
var querystring = require("querystring");
var contents = querystring.stringify({
username: '帐号',
password: '密码'
});
var options = {
hostname: '学校网址',
host: '学校网址',
path: '路径',
method: 'GET',
headers:{
"Content-Length":contents.length,
"Content-Type":"application/x-www-form-urlencoded"
}};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (data) {
console.log('BODY:' + data);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.write(contents);
req.end();
这是抓出来的东西
method我会用Get是因为学校是用Get传资料
如果我用Post的话会显示 405 Method Not Allowed
所以才用Get的