我使用node.js编写了一个API,因为我请求一个url广告,我将以json格式返回响应。
以下是我收到的部分:
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);
}但它的打印方式是某种编码字符串(我认为是这样),如下所示:
�1�
]d���!��w���^2���_#YP>3'y˥�p)�H�����S]}X;�yR�F�8所以尝试了base64译码器包,但它不工作,同样是打印。
同样,当我在浏览器中点击url时,我得到了以下json响应:
{
"error": {
"code": 404,
"message": "invalid_grant",
"error_description": "Invalid user credentials"
}
}但在我的密码里我收到了加密的密码。帮我解决这个问题。提前谢谢。
发布于 2014-07-17 09:31:01
我通过修改回复得到了答案,
我改变了:
return res.json({
"error": {
"code" : 404,
"message" : "invalid_grant",
"error_description": "Invalid user credentials"
}
})至:
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
}现在很好..。
https://stackoverflow.com/questions/24796752
复制相似问题