PhantomJS doesn't send authentication header

前端 未结 2 578
庸人自扰
庸人自扰 2020-12-14 01:42

I\'m trying to open a web page which requires HTTP authentication, in PhantomJS. My script is based off the loadspeed.js example:

var page = require(\'webpag         


        
2条回答
  •  抹茶落季
    2020-12-14 01:58

    I dont think there is anything wrong with the script your using or phantomjs (at least in v1.5).

    If you try this script:

    var page = require('webpage').create(),
        system = require('system'),
        t, address;
    
    page.settings.userName = 'test';
    page.settings.password = 'test';
    
    if (system.args.length === 1) {
        console.log('Usage: loadspeed.js ');
        phantom.exit();
    } else {
        t = Date.now();
        address = system.args[1];
        page.open(address, function (status) {
            if (status !== 'success') {
                console.log('FAIL to load the address');
            } else {
                t = Date.now() - t;
                console.log('Page title is ' + page.evaluate(function () {
                    return document.title;
                }));
                console.log('Loading time ' + t + ' msec');
            }
            phantom.exit();
        });
    }
    

    phantomjs loadspeed.js http://browserspy.dk/password-ok.php

    The auth is successful.

提交回复
热议问题