因为会点其它语言,其它语言我用的是unirest 最近在学nodejs , 因为unirest也支持nodejs平台 但一测了很久,都没模拟登陆成功,
var unirest = require('unirest'),
baseURL = "baseurl";
unirest.post(baseURL + "/Login")
.field('username', 'user') // Form field
.field('password', '******') // Form field
.field('remembername', '1') // Form field
.jar(true)
.end(function (response) {
console.log(response.body);
var cookies = response.cookies;
console.log(cookies);
unirest.get(baseURL + 'ProjectIndex')
.header("Cookie", cookies)
.end(function (data) {
console.log(data.body);
});
});
这样一直访问不到项目列表页,看返回的数据登陆是成功的
@DavidCai1993 感觉不会用的样子,拷了个示例…然后 npm install -g casperjs
workspace git:(master) ✗ node test.js
module.js:338
throw err;
^
Error: Cannot find module ‘casper’
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/coding/workspace/test.js:1:76)
at Module._compile (module.js:460:26)
at Object.Module._extensions…js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
➜ workspace git:(master) ✗ casperjs test.js
zsh: command not found: casperjs
➜ workspace git:(master) ✗