I am new to node.js, but I wanted to play around with some basic code and make some requests. Right now I'm playing with OCW search ( http://www.ocwsearch.com/ ), and I'm trying to make some basic queries using my sample search query:
However, no matter what request I try to make (even if I just request google.com), it returns me
<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>
I'm not too sure what is going on. I was looking for nginx, but most of the questions were asked about this, it seemed people were asking who set up their own servers. Instead, I tried using the https request, but this returns an "ENOTFOUND" error.
My code is below:
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/');
Sorry if this is a very simple question and thanks for any help you can give!
source share