I am trying to get a malformed HTTP response using node. Since the response is malformed, I cannot use request
normally (it would give the HPE_INVALID_CONSTANT
error)
From this answer https://stackoverflow.com/a/23543522/1748450 I can get the raw HTTP response using the net
module like so:
var net = require('net');
var host = '192.168.1.1',
port = 80,
socket = net.connect(port, host, function() {
var request = "GET / HTTP/1.1\r\nHost: " + host + "\r\n\r\n",
rawResponse = "";
// send http request:
socket.end(request);
// assume utf-8 encoding:
socket.setEncoding('utf-8');
// collect raw http message:
socket.on('data', function(chunk) {
rawResponse += chunk;
});
socket.on('end', function(){
console.log(rawResponse);
});
});
However, this only works with getting the response from the host's root page (192.168.1.1
). The page I'm trying to get the response from is actually 192.168.1.1/admin/landingpage.fwd
.
If I try to edit host
to that URL then I get this error:
events.js:187
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND 192.168.1.1/admin/landingpage.fwd
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
Emitted 'error' event on Socket instance at:
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: '192.168.1.1/admin/landingpage.fwd'
}
Is this possible to fetch this using the net
module in the above example?
If not possible, what other way can I use to get the raw HTTP response from that URL?