RafDev RafDev - 1 year ago 151
Node.js Question

Make HTTP GET request using Node.js

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)})

console.log("Request to '" + filename + "' failed: " + e.message)


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download