【问题标题】:How to form url and send http request with data in Node.js如何在 Node.js 中形成 url 并发送带有数据的 http 请求
【发布时间】:2015-11-03 06:46:41
【问题描述】:

我想用下面的“原始请求”形成 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!"}}

谢谢。

【问题讨论】:

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


    【解决方案1】:

    您可以使用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
    })
    

    【讨论】:

    • 太棒了!将此问题标记为已回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多