I am attempting to send a POST request to a server I have no control over. The server receives the POST but then sends a response every time an external event happens. So by "subscribing" with one POST I should be able to receive multiple responses until the connection is dropped. I have attempted to do this using sockets, but it seems the socket sends as TCP which the server does not recognise - it needs to be HTTP (I checked this using Wireshark as they have an APITool with which to test the connection).
This is my code to receive the data:
var net = require("net");
var client = new net.Socket();
client.connect(
8080,
"hostname.com",
function() {
console.log("Connected");
client.write(`POST /Subscribe HTTP/1.1
Authorization: Basic authcode
Host: hostname.com:8080
Content-Length: 1078
Connection: keep-alive
Keep-Alive: 300
<?xml version="1.0" encoding="UTF-8"?>
<config version="1.7">
... (some XML here)
</config>
`);
console.log("Finished Write");
}
);
client.on("data", function(data) {
console.log("Received " + data.length + " bytes\n" + data);
});
client.on("close", function() {
console.log("Connection closed");
});
client.on("error", function(err) {
console.log("Connection error" + err);
});
client.on("end", function(err) {
console.log("Connection end" + err);
});
Is there a way to force the socket to send as HTTP, or is there a way to receive a "stream" from a POST request over http?
Thank you.
EDIT 1: Adding the raw HTTP code whePOST /SetSubscribe HTTP/1.1
Host: hostname.com:8080
Keep-Alive: 300
Authorization: Basic authkey
Content-Type: application/xml
Content-Length: 1076
<?xml version="1.0" encoding="UTF-8"?>
... XML
</config>
And this gives the response:
<?xml version="1.0" encoding="UTF-8" ?>
<config version="1.7" xmlns="http://www.ipc.com/ver10">
... XML
</config>
With the following headers:
Content-Type: application-xml
Content-Length: 397
Connection: keep-alive
When I watch this in WireShark I see multiple responses coming back but I don't know how to "grab" them in code to use them. Postman doesn't show each of these new responses coming back though.