Jatin Jatin - 1 year ago 93
Javascript Question

GET rest call in Node.js not showing output in JSON

I have written a GET rest call in node.js. My post call works fine but when I use the get call I don't see output in Json format. Infact I see output in some special character. Please advice where I am going wrong.

var http = require('http');
var requestrespone = require("request");
var config = require('../config/config.js');
var jsonFile = require('jsonfile');
var jsonFile=require('../json_input/jsoninput.json');
var cheerio =require('cheerio');
var express=require('express');
var app=express();
var postOptions = {
host : config.host,
method : config.post,
path: config.path,
headers :config.postheader

var getOptions=
host : config.host,
method : config.get,
path: config.getpath,
headers :config.getheader


jsonObject = JSON.stringify(jsonFile);

console.info('Options prepared:');
console.info('Starting the POST call');

var jsonString;
function mapFeedbackIdGeneration(done)

var reqPost = http.request(postOptions, function(res) {
console.log("statusCode: ", res.statusCode);
res.on('data', function(data) {
return done(jsonString);

res.on('close', function() {

reqPost.on('error', function(e) {
///----------GET CALL----------------->>>>>
console.info('Options prepared:');

console.info('Do the GET call');

var options = {
"method": "GET",
"hostname": "maphub.cit.api.here.com",

"path": "/feedback/-936624",
"headers": {

'Authorization':'AWS O7Qx6dyYEnwwBT2Hn5Es:gR/rjtlGsggWEZ1ItPOw0oGXdPM=',


'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0',



var req = http.request(options, function (res) {
var chunks = [];

res.on("data", function (chunk) {
console.log("chunks data");

res.on("end", function () {
var body = Buffer.concat(chunks);



My output should be JSON data but it shows :

Do the GET call
chunks data
hello▼ T?AO?0►????8?‼?"?*??j↨q@=L?i?%???¶§?⌂?I`w?↨?~??,??? ?.♀???,?
"?X(D?PKA‼G????????KD?????j>X?p?`??%$ ?▼^!
?i/!b?n??`?!∟???=?4g?B?????j?yXln?[??)?D▲?wzIj?@?¶[N?4F}u ??]?d\=?n?{▲3??n
►???♥??7?‼?♂??\G?S$?♠2YF{?♥>n??5m?▼???/? ??q?y}??>)??????♫??\????7 ??♥ ☼??↑☻

statusCode: 200

Where am I going wrong?

Answer Source

There is issue in your code. Remove the following in options variable.


Above line tells the remote server that client can accept gzip compressed file and can decompress it. But, your application doesn't do the decompression part. Hence, you are seeing the gibberish data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download