nodejs发送http请求接受回来的数据怎么写入页面
展开全部
var body=reqs.body;//迅郑蚂发亩埋送的字段{colNum,currentPage}
console.log(“colNum”+JSON.stringify(body));
var contentStr=queryString.stringify(body);
var opt={
“hostname”:url.parse(urlStr).hostname,
“path”:url.parse(urlStr).path,
“method”:“POST”,
“port”:3000,
“headers”:{
.......
var httpModule = urlStr.indexOf(‘https’) === 0 ? https : http;
var req = httpModule.request(opt, function(httpRes) {
var buffers = [];
httpRes.on(‘data’, function(chunk) {
buffers.push(chunk);
});
httpRes.on('end', function(chunk) {
var wholeData = Buffer.concat(buffers);
var dataStr = wholeData.toString('utf8');
console.log('content'+wholeData);
data=wholeData;
/丛培/res.send(JSON.stringify(buffers));
});
}).on('error', function(err) {
console.log('error ' + err);
});;
//写入数据,完成发送
req.write(contentStr);
req.end();
res.send(JSON.stringify(data));
console.log(“colNum”+JSON.stringify(body));
var contentStr=queryString.stringify(body);
var opt={
“hostname”:url.parse(urlStr).hostname,
“path”:url.parse(urlStr).path,
“method”:“POST”,
“port”:3000,
“headers”:{
.......
var httpModule = urlStr.indexOf(‘https’) === 0 ? https : http;
var req = httpModule.request(opt, function(httpRes) {
var buffers = [];
httpRes.on(‘data’, function(chunk) {
buffers.push(chunk);
});
httpRes.on('end', function(chunk) {
var wholeData = Buffer.concat(buffers);
var dataStr = wholeData.toString('utf8');
console.log('content'+wholeData);
data=wholeData;
/丛培/res.send(JSON.stringify(buffers));
});
}).on('error', function(err) {
console.log('error ' + err);
});;
//写入数据,完成发送
req.write(contentStr);
req.end();
res.send(JSON.stringify(data));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询