• Using http.get():

    http.get(options, function(res) {
    	print("available: " + res.available());						//returns 168
    	print("Content-Length: " + res.headers['Content-Length']);	//returns 300
    	print("Manual read: " + res.read())
    
    	res.on('data', function(data) {
    		print("\t Response: code: " + res.statusCode);      
    		print("--> " + data);
    	});
    
    	res.on('close', (data) => print("close: " + data));	//for debugging
    	res.on('drain', (data) => print("drain: " + data));	//for debugging
    	res.on('error', (e) => print("Error: " + e));			//for debugging
    });
    
    req.on('error', function(e) {
    	print("ERROR", e);
    });
    

    Results:

    available: 168
    Content-Length: 300
    Manual Read: [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t
    code: 200
    --> [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t

    Using http.request:

    var req = http.request(options, function(res) {
    	print("available: " + res.available());						//returns 168
    	print("Content-Length: " + res.headers['Content-Length']);	//returns 300
    	print("read: " + res.read())
    
    	res.on('data', function(data) {
    	  print("\t Response: " + "code: " + res.statusCode);
    	  print("--> " + data);
    	});
    });
    
    req.on('error', function(e) {
        print("error: " + e);
    });
    

    Results:

    available: 168
    Content-Length: 300
    Manual Read: [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t
    code: 200
    --> [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t

    I also tried concatenating a string with each data that is returned:

    tempMsg = "";
    var req = http.request(options, function(res) {
    	var l = res.headers['Content-Length'];
    	print("l = " + l);
    	res.on('data', function(data) {
    		tempMsg += data;
    		if (tempMsg.length >=1) {
    		print("tempMsg: " + tempMsg);
    		print("End of Message");
    		}
    	});
    	res.on('close', function(data) {
    		print("\t Response: " + "code: " + res.statusCode);
    	});
    	res.on('error', (e)=> print("error: " + e));    //for debugging
    });
    
    req.on('error', function(e) {
    	if (callback) callback(e.code, e.message);
    });
    
    req.end(body);
    

    Results:

    l = 300
    [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t
    tempMsg: [{"type":"Positioning","accelerometer":true,"trilateration":true,"globalPositioning":true},{"type":"EventCadence","smartMode":true},{"type":"Environmental","humidity":t
    End of Message
    code: 200

About

Avatar for Nadnerb @Nadnerb started