【问题标题】:How to send push notification with "npm request" to ionic API?如何向离子 API 发送带有“npm 请求”的推送通知?
【发布时间】:2016-09-01 21:56:33
【问题描述】:

我尝试通过具有“npm 请求”的 ionic API 推送通知。我的代码:

var request = require('request');
var token = '................';

var title = escapeJson('title 123');
var message = escapeJson('message 123');

var req = {
  method: 'POST',
  url: 'https://api.ionic.io/push/notifications',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token
  },
  data: {
    "tokens": ["........"],
    "profile": "pushserver",
    "notification": {
      "title": title,
      "message": message,
      "android": {
        "title": title,
        "message": message
      }
    }
  }
};

我收到此错误:

{"meta": {"version": "2.0.0-beta.0", "status": 422, "request_id": “853be189-87e0-4636-b58a-aca58cef63b3”},“错误”:{“消息”:“无效 请求正文中的 JSON。对于空 JSON,传递 '{}'。", "type": "UnprocessableEntity", "link": null}}

有人知道是什么问题吗?

谢谢

【问题讨论】:

    标签: node.js ionic-framework npm request ionic2


    【解决方案1】:

    我将“数据”更改为“正文”,现在它可以工作了:

    var req = {
      "method": "POST",
      "url": "https://api.ionic.io/push/notifications",
      "headers": {
        "Content-Type": "application/json",
        "Authorization": "Bearer " + token
      },
      "body": {
        "tokens": ["........"],
        "profile": "pushserver",
        "notification": {
          "title": title,
          "message": message,
          "android": {
            "title": title,
            "message": message
          }
        }
      }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 2016-04-21
      • 2018-12-31
      • 1970-01-01
      相关资源
      最近更新 更多