2017-07-28 189 views
0

我需要將以下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/.... 

回答

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

它的工作!謝謝 –