如何在Node.js

时间:2015-11-03 06:46:42

标签: javascript node.js http http-headers npm-request

我想用下面的“Raw Request”形成url,然后在nodejs中向它发送请求,我该怎么办呢。


Raw Request:
-----------

POST /sky?api_key="" HTTP/1.1
Host: https://sky.in
Content-Type: application/json
Connection: close
Content-Length: 82
{"registration_ids":[""], "data":{"message":"Hello World!"}}


谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用request模块:

var request = require('request')
request.post('https://sky.in/sky', {
  qs: {
    api_key: ''
  },
  json: {
    registration_ids: [],
    data: {message: 'Hello World!'}
  },
}, function (err, res, body) {
  // body contains the parsed JSON response
})