![](/img/trans.png)
[英]HTTP request in node.js returning response.statuscode as forbidden
[英]Returning object in http response with NODE.JS
我想将sql查询结果对象从http服务器发送回客户端。 我收到此错误:“ TypeError:第一个参数必须是字符串或缓冲区”
如果我将响应内容转换为字符串,则可以正常工作,但对我而言却毫无用处。
该问题的解决方案是什么? 也许还有另一种方式来做出http响应,还是其他?
retrieve.retrieveAllStores(function(data){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(data);
res.end();
});
您可以尝试使用JSON.stringify()
将数据转换为字符串,然后使用JSON.parse()
转换回JS对象。
retrieve.retrieveAllStores(function(data){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(JSON.stringify(data));
res.end();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.