0

I'm trying to make an HTTP GET request using Node.js but it errors

Request to '/path/to/file?query=string' failed: read ECONNRESET

How may I fix it? Thanks in advance. It was working before, I'm not sure of what changed.

var http = require("http");
var data = "";

var options = {
    host: "sub.example.com",
    port: 80,
    path: "/path/to/file?query=string",
    method: "GET",
};

var req = http.request(options, function(resp){
    resp.on('data', function(_data){data = data + _data});
    resp.on('end', function(){callback(data)})
});

req.on('error',function(e){
    console.log("Request to '" + filename + "' failed: " + e.message)
});

req.write('data\n');
req.write('data\n');
req.end();
mplungjan
  • 169,008
  • 28
  • 173
  • 236
R__
  • 183
  • 2
  • 11

1 Answers1

0

GET requests typically do not have a body. Try removing the req.write() lines and you may have better luck.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • I believe it worked, but I'm not sure if before the server was just overfloading. – R__ Jul 16 '16 at 16:03