用node.js请求重写curl

时间:2017-07-28 21:59:58

标签: node.js curl

我需要将以下curl查询编码为node.js请求。 我知道表单应该可以完成这项工作,但我不知道如何处理“payload =”

curl -X POST --data-urlencode 'payload={"channel": "#tutorial", "username": "webhookbot", "text": "This is posted to #tutorial and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/T5NGB8FE0/B6G57N86A/....

1 个答案:

答案 0 :(得分:1)

也许是这样的:

request.post({
    url: 'https://hooks.slack.com/services/T5NGB8FE0/B6G57N86A/',
    form: {
      payload: '{"channel": "#tutorial", "username": "webhookbot", "text": "This is posted to #tutorial and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}'
    }
  }, (error, response, body) => {
     //your code
  }
);