私は基本的に/ etc/hostsファイルのIPアドレスにマップされた内部URLを持っています。 URLにpingを実行すると、正しい内部IPアドレスが返されます。私はrequest
ノードモジュールに依存していたときに、問題が発生する:/etc/hostsの使用を強制的に要求する
の/ etc/hosts:
123.123.123.123 fakeurl.com
app.js:
403エラー:
var request = require('request');
request('http://fakeurl.com/', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the page.
});
は200のコードを動作します。
をvar request = require('request');
request('http://123.123.123.123/', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the page.
});
ノードアプリケーション内でDNSマッピングを強制する方法はありますか?
代わりにhttpモジュールを使用して試すことができますか? httpモジュールは/ etc/hostsに従って解決する必要があります。 – user3105700
これは簡単だったと思います。実際に別のノードモジュールによって実行されているため、リクエストモジュールに縛られています。私はちょうどそれがなぜ起こって、それをバイパスする方法を見つけることを望んでいたの問題を絞りました。 – Woodsy
私はこの同じ問題に直面しています。 Node.jsがhostsファイルを無視してリクエストを作成し続ける理由はわかりません。何か解決策を見つけましたか? – JamesYin