我是node.js的新手,但我想玩弄一些基本代碼併發出一些請求。目前,我正在玩OCW搜索(http://www.ocwsearch.com/),我正在嘗試使用他們的示例搜索請求提出幾個基本請求:Node.js返回301重定向的請求
但是,無論我嘗試提出什麼要求(甚至如果我只是查詢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/');
很抱歉,如果這是一個非常簡單的問題,並感謝!
這是一大堆$。 – Krinkle