[英]NodeJS DNS error: ENOTFOUND
我收到以下錯誤: getaddrinfo ENOTFOUND
。 我嘗試連接的URL是HTTPS上的子域。
var options =
{
family: 4,
hostname: 'test.printapi.nl',
port: 443,
path: '/v1/oauth',
method: 'POST',
requestCert: true,
headers: {
host: 'https://test.printapi.nl',
//'User-Agent': USER_AGENT,
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
}
};
options.agent = http.Agent(options);
var req = http.request(options, (res) => {
console.log('statusCode: ', res.statusCode);
console.log('headers: ', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
}, data);
console.log(data)
req.write(data)
req.end();
req.on('error',function(e){
console.log("Error: " + e.message);
console.log( e.stack );
});
我已經嘗試了很多方法,包括路徑,主機名等。使用fiddler時,我需要設置一個代理,fiddler將解析test.printapi.nl的主機名,並進行身份驗證。 但是,當節點需要執行此操作時,它找不到正確的DNS記錄。
我嘗試了dns.getServers()
,它確實返回了正確的DNS服務器。 我也嘗試了谷歌的DNS服務器,並沒有幫助。 我是否忽略了需要設置的主機名才能解決的問題?
--EDIT如果我使用https, cannot read property 'maxCachedSessions'
提前致謝!
ENOTFOUND
表示未找到hostname
DNS條目。 在這種情況下的問題是, hostname
不應該包括路徑 。 相反,它應該看起來像:
var options = {
hostname: 'test.printapi.nl',
path: '/v1/oauth'
// ...
另外,您不需要顯式設置Host
標頭。 port
號與您所使用的模塊不同-如果是https連接,請使用https.request()
而不是http.request()
。
最后,您可以刪除或需要更改此行:
options.agent = http.Agent(options);
對此:
options.agent = new https.Agent(options);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.