Tuesday 16 May 2017

HTTP GET request (Node) returns 501

I'm testing fake HTTP requests on Node. But I get the same result (501) on the headers defining GET, POST methods or "FOO". I don't understand the output. Can someone give me a hint? The code:

var http = require('http');
var fs = require('fs');


var options = {
    method: "FOO" //or GET 
    , uri: 'https://www.google.com'


};

var callback = function(response){
   var exportJson= JSON.stringify(response.headers);
   var arrayData =[];
   response.on('data', function(data) {
      arrayData += data;

   });

   response.on('end', function() {
     console.log('THE DATA IS ' + arrayData);


   });
    fs.appendFile("input.txt", exportJson, function(err) {
    if(err) {
        return console.log(err);
        }
    });

}



var req = http.request(options, callback); 


function test(){

for (var prop in options.method) {
  //console.log(`options.method${prop} = ${options.method[prop]}`);
   //console.log(req);
  req;
}

}

test();     
req.end();

"GET" or "FOO" methods the console says:

<h2>HTTP ERROR 500.19 - Internal Server Error</h2>



via glassraven

No comments:

Post a Comment