使用phantomjs的Windows身份验证 [英] Windows authentication using phantomjs

查看:113
本文介绍了使用phantomjs的Windows身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的最新项目中,我正在寻找phantomjs作为UI自动化的可能解决方案,但似乎无法使Windows身份验证正常工作.我尝试设置page.settings.userNamepage.settings.password,但是下面的代码段始终获得 401 ,并且基础堆栈不费力气来解决它.我的搜索引擎优化使我失败了,所以我来到社区寻求帮助.

I'm looking into phantomjs as a possible solution for UI automation in my latest project, but I can't seem to get windows authentication to work properly. I've tried setting the page.settings.userName and page.settings.password, but the snippet below always gets a 401 and the underlying stack makes no effort to resolve it. My search-fu has failed me, so I come to the community to ask for help.

var page = require('webpage').create();

page.onResourceReceived = function(response) {
    phantom.exit(response.status);
};

page.open('http://bing.com');

推荐答案

对我来说,这种情况非常有效. 迈克·罗杰斯解决方案

For me this case works perfect. mike-rogers solution

var _driverOptions = new PhantomJSOptions();
var _driverService = PhantomJSDriverService.CreateDefaultService();
_driverOptions.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
_driver = new PhantomJSDriver(_driverService, _driverOptions);


using (Impersonation.LogonUser(domain, login, pass, LogonType.Interactive))
{
    using (var proxy = new NtlmProxy(new Uri("http://yoursite.com/"), options))
    {
        _driver.Navigate().GoToUrl(url);
    }
 }

这篇关于使用phantomjs的Windows身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆