登录页面:http://www.hooyid.com/login.jsp 找到登录提交的地址: var form=document.loginForm; form.action="/frontlogin/in"; form.submit();
使用node模拟登录时,返回代码为404,登录不成功,是网站做了其它未知的防护吗?登录页面没看到有何特别的代码,该如何模拟登录呢?
附代码: var UTIL = require(“util”); var HTTP = require(“http”); var HTTPS = require(“https”); var URL = require(“url”); var HTMLPARSER = require(“htmlparser2”); var FORMDATA = require(“form-data”);
var username = ""; var password = "";
var login = function(cb){ var form = new FORMDATA(); form.append(“username",”"); form.append(“password",”"); var options = { host: 'www.hooyid.com’, path: '/frontlogin/in’, method: 'POST’, headers: { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-US,en;q=0.5", "Connection": "keep-alive", "Host": "www.hooyid.com", "Referer": "http://www.hooyid.com/login.jsp", "User-Agent": “Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0” } };
// 发送带表单请求
form.submit(options, function(err, res){
if(err){
cb(err);
}else{
var headers = JSON.stringify(res.headers);
console.log('STATUS2: ' + res.statusCode);
console.log('HEADERS2: ' + headers);
res.setEncoding("utf8");
var res_body = "";
res.on("data", function(chunk) {
res_body += chunk;
});
res.on("end", function(){
//console.log('DATA2: ' + res_body);
});
res.on("error", function(err2){
console.error(err.message);
cb(err2);
});
}
});
};
login(function(err){
if(err){
console.log("login_post error.", err.message);
return;
}
var headers = JSON.parse(headers);
HTTP.get(headers.location, function (res) {
res.setEncoding("utf8");
var res_body = "";
res.on("data", function(chunk) {
res_body += chunk;
});
res.on("end", function(){
console.log('DATA3: ' + res_body);
});
res.on("error", function(err2){
console.error(err.message);
});
});
});