I have written an API using node.js, in that i request for a url ad i will return the response in json format
Following is my receiving part:
try{
proxyRes.on("data", function(chunk) { //Capture API response here---revisit
body = chunk.toString();
console.log("Inside data=" + (body));
});
} catch(err){
console.log("errrr=" +err.stack);
}
But its printing as some encoded string(I think so) like below:
�1�
]d���!��w���^2���_#YP>3'y˥�p)�H�����S]}X;�yR�F�8
So tried for base64 decoder package, but its not working, the same is printing.
Also when i hit the url in browser i am getting the following json response:
{
"error": {
"code": 404,
"message": "invalid_grant",
"error_description": "Invalid user credentials"
}
}
But in my code i am receiving encrypted code. Help me to solve this. Thanks in advance.
I got the answer by modifying the response,
I changed:
return res.json({
"error": {
"code" : 404,
"message" : "invalid_grant",
"error_description": "Invalid user credentials"
}
})
TO:
res.writeHead(400, {'Content-Type': 'application/json'});
res.end(JSON.stringify({
"error": {
"code" : 404,
"message" : "invalid_grant",
"error_description": "Invalid user credentials"
}
}, null, "\n"));
return;
//return res.redirect('/login');//signin
}
It works fine now..