0
我必须发送String类型的一些参数以及我身体中的一个数组。 但它抛出我的错误消息:在请求正文中传递数组或嵌套对象npm
第一个参数必须是字符串或缓冲区
这里是我的代码:
var tokenList = JSON.parse(req.body.tokenList);
var mobParams = {
"tokens": tokenList,
"profile": "<myprofile>",
"notification": {
"title": req.body.title,
"message": req.body.text
}
};
request({
method: "POST",
url: 'https://api.ionic.io/push/notifications',
headers: {
"content-type": "application/json",
"authorization": "Bearer ********"
},
body: (mobParams)
}, function(error, response, body){
console.log('Ionic push error', error);
console.log('IOnic push res', response);
console.log('IOnic push body', body);
if(!error){
return res.send({
code: 1,
message: "success"
});
}else{
return res.send({
code: 0,
message: error
});
}
如何传递这个对象在我的阵列请求npm?
另外,我想补充一点,这个实现在前端运行相当好,但我有单独的代码库,它需要我点击多个FCM请求,即循环。所以,我很高兴有一个解决方案,既不离子推也不FCM推工程
对于FCM推我想下面的代码:
let desktopParams = {
"notification": {
"title": 'Merchant Portal Notifications',
"body": req.body.text
// "click_action" : action
},
"to": '/topics/' + topic
};
request({
method: "POST",
json: true,
url: 'https://fcm.googleapis.com/fcm/send',
headers: {
"content-type": "application/json",
"authorization": "key=****"
},
body: desktopParams
}, function(error, response, body){
console.log('error', error);
console.log('response', response);
console.log('body', body);
//return body;
});
尽量'体:JSON.stringify(mobParams)' – Ajay
试过。通话无法解决。没有错误,没有任何控制台。 – kushalvm
在请求头中添加'“Content-Length”:JSON.stringify(mobParams).length' – Ajay