Javascript 使用node.js进行Phantomjs身份验证以访问mean.js页面
我需要使用phantomjs访问mean.js网站页面。问题是我不知道在标题中包含什么来实现它 我可以使用http.request进行身份验证并获取用户对象。但是我需要以某种方式获取这些信息并将其放在phantomjs头中,以允许访问页面 下面是一些代码:Javascript 使用node.js进行Phantomjs身份验证以访问mean.js页面,javascript,node.js,authentication,phantomjs,meanjs,Javascript,Node.js,Authentication,Phantomjs,Meanjs,我需要使用phantomjs访问mean.js网站页面。问题是我不知道在标题中包含什么来实现它 我可以使用http.request进行身份验证并获取用户对象。但是我需要以某种方式获取这些信息并将其放在phantomjs头中,以允许访问页面 下面是一些代码: 'use strict'; var phantom = require('node-phantom-simple'); phantom.create({ path: require('phantomjs').path }, functio
'use strict';
var phantom = require('node-phantom-simple');
phantom.create({ path: require('phantomjs').path }, function (err, browser) {
if (err) {
console.log(err);
}
else {
browser.createPage(function (err, page) {
if (err) {
console.log(err);
}
else {
//this is wrong - does not work with mean.js/passport authentication
var authentication_data = { 'Authorization': 'Basic ' + new Buffer('<user>:<password>').toString('base64') };
page.set('customHeaders', authentication_data, function (err) {
if (err) {
console.log(err);
}
else {
var htmlPath = 'http://localhost:3000/path-to-my-web-page';
var complete = false;
page.onConsoleMessage = function (msg) {
console.log('Console: %s', msg);
if (msg === 'the page is loaded') complete = true;
};
return page.open(htmlPath, function (err, status) {
console.log('opened page ', status);
if (err) {
console.log('page.open', err);
}
else {
console.log('opened ' + htmlPath);
//stuff happens here after page is loaded
}
});
}
});
}
});
}
});
“严格使用”;
var phantom=require('node-phantom-simple');
create({path:require('phantomjs').path},函数(err,浏览器){
如果(错误){
控制台日志(err);
}
否则{
browser.createPage(函数(错误,第页){
如果(错误){
控制台日志(err);
}
否则{
//这是错误的-不适用于mean.js/passport身份验证
var authentication_data={'authentication':'Basic'+新缓冲区(':')。toString('base64')};
page.set('customHeaders',身份验证数据,函数(err){
如果(错误){
控制台日志(err);
}
否则{
var htmlPath='1〕http://localhost:3000/path-到我的网页';
var complete=false;
page.onConsolleMessage=函数(msg){
日志('console:%s',msg);
如果(msg==‘页面已加载’)complete=true;
};
返回页面。打开(htmlPath,函数(错误,状态){
console.log('打开的页面',状态);
如果(错误){
console.log('page.open',err);
}
否则{
console.log('opened'+htmlPath);
//加载页面后,这里会发生一些事情
}
});
}
});
}
});
}
});
我错过了一篇文章,上面说可以访问该页面
谢谢你的帮助