admin管理员组文章数量:1415420
Im trying to access a resource from the web throught a proxy. Unlike this response, I need to set a domain\user and password authentication.
Well, this is my code:
var http = require('http');
var options = {
host: "proxy.domain",
port: 80,
path: "",
headers: {
Host: "www.google"
},
method: 'GET',
auth: 'domain\\user:password'
};
http.request(options, function (data) {
console.log('success!', data);
}).on("error", function (e) {
console.log('error :(', e);
});
The code above is thowing inmediatly the following error:
error :( { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
So, no request being sent, I guess.
What is wrong? How can I send a request with the parameters I trying to set?
Thanks in advance
Im trying to access a resource from the web throught a proxy. Unlike this response, I need to set a domain\user and password authentication.
Well, this is my code:
var http = require('http');
var options = {
host: "proxy.domain.",
port: 80,
path: "http://www.google.",
headers: {
Host: "www.google."
},
method: 'GET',
auth: 'domain\\user:password'
};
http.request(options, function (data) {
console.log('success!', data);
}).on("error", function (e) {
console.log('error :(', e);
});
The code above is thowing inmediatly the following error:
error :( { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
So, no request being sent, I guess.
What is wrong? How can I send a request with the parameters I trying to set?
Thanks in advance
Share Improve this question edited May 23, 2017 at 11:47 CommunityBot 11 silver badge asked Mar 18, 2014 at 18:22 lantelante 7,3564 gold badges38 silver badges59 bronze badges2 Answers
Reset to default 4this code worked for me (encoding in base64 and setting Proxy-Authorization in headers):
var username = 'yourUsername';
var password = 'yourPass';
var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64');
var options = {
host: "proxy",
port: 8080,
path: "https://www.google.",
headers: {
Host: "www.google.",
"Proxy-Authorization" : auth
}
};
Here is an updated version
var.auth = "username" : "password";
http.get({
host : var.hostname,
port : var.port,
path : requestUrl.href,
headers: {
Host : requestUrl.host,
'Proxy-Authorization': `Basic ${new Buffer(var.auth).toString('base64')}`,
}
}, response => {
//do what you want with response
})
本文标签: javascriptnodejs http with proxy and domainuserpassword authorizationStack Overflow
版权声明:本文标题:javascript - node.js http with proxy and domainuser:password authorization - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745214575a2648086.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论