私は node.js を初めて使用しますが、いくつかの基本的なコードをいじって、いくつかのリクエストを行いたいと思っていました。現時点では、OCW 検索 ( http://www.ocwsearch.com/ ) をいじっており、サンプルの検索要求を使用していくつかの基本的な要求を作成しようとしています。
ただし、どのようなリクエストをしようとしても(google.comにクエリを実行しただけでも)、返されます
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/0.7.65</center>
</body>
</html>
何が起こっているのかよくわかりません。私はnginxを調べましたが、それについて尋ねられたほとんどの質問は、独自のサーバーをセットアップしていた人々から尋ねられたようです. 代わりに https リクエストを使用してみましたが、「ENOTFOUND」というエラーが返されます。
以下の私のコード:
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
var options = {
host:'ocwsearch.com',
path:
'/api/v1/search.json?q=statistics&contact=http%3a%2f%2fwww.ocwsearch.com%2fabout/',
method: 'GET'
}
var req = http.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
これが非常に単純な質問である場合は申し訳ありません。あなたができる助けに感謝します!