小编mam*_*one的帖子

https请求基本认证node.js

我真的很疯狂地在网络和 stackoverflow 上寻找这个。关于此主题的其他帖子讨论的是 http 请求,而不是 httpS。

我正在使用 node.js 编码服务器端,我需要向另一个网站发出 https 请求才能登录

如果我在 Chrome 中使用邮递员工具尝试使用https://user:pass@webstudenti.unica.it/es​​se3/auth/Logon.do一切正常并且我登录。

如果我在节点中使用请求库,我将无法登录,并且会收到一个页面,其中包含有关获取/发送数据中的错误的自定义错误消息。

也许我错误地设置了传递给请求的选项。

var request = require('request');
var cheerio = require('cheerio');
var user =  'xxx';
var pass = 'yyy';
var options = {
    url : 'https://webstudenti.unica.it',
    path : '/esse3/auth/Logon.do',
    method : 'GET',
    port: 443,
    authorization : {
        username: user,
        password: pass
    }
}

request( options, function(err, res, html){
    if(err){
        console.log(err)
        return
    }
    console.log(html)
    var $ = cheerio.load(html)
    var c = $('head title').text();
    console.log(c);
})
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/985bs0sc/1/

javascript authentication https node.js

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

authentication ×1

https ×1

javascript ×1

node.js ×1