如何形成 url 并使用 Node.js 中的数据发送 http 请求
How to form url and send http request with data in Node.js
我想用下面的 "Raw Request" 形成 url 然后在 nodejs 中向它发送请求,我该怎么做。
<b>Raw Request:</b>
-----------
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!"}}
谢谢。
您可以使用 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
})
我想用下面的 "Raw Request" 形成 url 然后在 nodejs 中向它发送请求,我该怎么做。
<b>Raw Request:</b>
-----------
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!"}}
谢谢。
您可以使用 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
})