我得到这个控制台输出。我的代码非常简单。我的公司使用Squid ntlm代理,所以我使用cntlm代理使事情变得更容易。但是,我不能使用cntlm代理来制作节点应用程序。我需要帮助。
All is well!
You hit http.get
407
Proxy Authentication Required
{ server: 'squid/4.6',
'mime-version': '1.0',
date: 'Sat, 12 Jun 2021 14:19:33 GMT',
'content-type': 'text/html;charset=utf-8',
'content-length': '3490',
'x-squid-error': 'ERR_CACHE_ACCESS_DENIED 0',
vary: 'Accept-Language',
'content-language': 'en',
'x-cache': 'MISS from centry',
'x-cache-lookup': 'NONE from centry:3128',
via: '1.1 centry (squid/4.6)',
connection: 'close',
'proxy-authenticate': 'Basic realm="Cntlm for parent"' }我的代码:
const express = require('express');
const http = require('http');
const app = express();
app.get("/get", function(req,res){
var opts = {
host: '127.0.0.1',
port: 3128,
path: "http://www.google.com:80",
};
var req = http.get(opts, function(res) {
console.log("You hit http.get");
console.log(res.statusCode);
console.log(res.statusMessage);
console.log(res.headers);
});
})
app.listen(3000,function(){
console.log("All is well!");
})发布于 2021-06-13 04:15:14
我在12个小时后找到了解决方案!
var opts = {
host: '127.0.0.1',
port: 3128,
path: "http://url.com",
headers: {
'Connection' : 'keep-alive',
}
};如果你将路径改为"http://google.com"“,你会得到301代码(永久移动),因为google.com正在以某种方式重定向。
所有的点都在
headers: {
'Connection' : 'keep-alive',
}https://stackoverflow.com/questions/67949773
复制相似问题