用node.js请求重写curl

问题描述:

我需要将以下curl查询编码为一个node.js请求。 我知道,形式应该做的工作,但我不知道何来处理“有效载荷=”用node.js请求重写curl

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/.... 

也许是这样的:

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 
    } 
); 
+0

它的工作!谢谢 –