Node.js HTTP post请求,回调数据老是报错Can't set headers after they are sent
Error: Can’t set headers after they are sent.
var httpreq = require('request');
....
..
kuaidi: function (req, res) {
var ShipperCode = 'SF';
var LogisticCode = '033813206167';
if (sails.config.system.ShopConfig.logistics_open && sails.config.system.ShopConfig.logistics_info) {
var logistics_info = sails.config.system.ShopConfig.logistics_info;
if ('kdn' == logistics_info.lg_appname) {
var obj = {
OrderCode: '',
ShipperCode: ShipperCode,
LogisticCode: LogisticCode
};
var RequestData = JSON.stringify(obj);
var DataSign = StringUtil.base64Encode(md5(RequestData + logistics_info.lg_appkey));
httpreq.post('http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx',{form:{
'EBusinessID': logistics_info.lg_appid,
'RequestType': '1002',
'RequestData': encodeURI(RequestData),
'DataSign': DataSign,
'DataType': '2'
}}, function (e, r, body) {
if (!e && r.statusCode == 200) {
return res.json({code: 0, msg: '', data: JSON.parse(body)});//这里报错啊。。。
}else{
return res.json({code:1,msg:'err'});
}
});
} return res.json({code:1,msg:'err'});
} else
return res.json({code:1,msg:'err'});
}