I am trying to execute a GET request from node.js. This request is for a REST server that will access Hbase and return data. A GET request contains all the necessary Hbase information (table, key, column family, etc.). Below is the code.
var http = require('http');
var url = {
host: '127.0.0.1',
port: 8000,
path: '/table-name/key/column-family',
headers: {
'Content-Type': 'application/octet-stream'
},
};
http.get(url, function(resp){
console.log("Status: " + resp.statusCode);
console.log("Header: " + JSON.stringify(resp.headers));
resp.setEncoding('utf8');
var completeResponse = '';
resp.on('data', function (chunk) {
completeResponse += chunk;
});
resp.on('end', function(chunk) {
console.log(completeResponse);
});
});
My problem is that the response I get is not always an octet stream on request. Most time data is in a valid format with a header, as shown below.
{"content-length":"454","x-timestamp":"1395469504346","content-type":"application/octet-stream"}
But, say, 1 out of 10 times, the response is an XML string with a heading like the following.
{"content-type":"text/xml","content-length":"793"}
In both cases, the status code is 200, and I always request an existing key. This behavior seems random and is not caused by any particular key.
, , XML/JSON?