I'm trying to make an HTTP Request function. All requests go to the same directory on the same domain, only the file name is different.
Nothing is coming up in the console, and it's not returning anything.
function HttpRequest(filename){
var options = {
host: "example.com",
port: 80,
path: "/path/to/file/" + filename,
method: "GET",
};
var Response = "";
var StatusCode = 0;
var req = http.request(options, function(resp){
resp.on('data', function(data){
Response = data;
StatusCode = resp.statusCode;
});
});
req.on('error',function(e){
console.log("Request to '" + filename + "' failed: " + e.message)
});
req.write('data\n');
req.write('data\n');
req.end();
return Response;
}