如何在NodeJS中发送ZAP发布请求?

时间:2020-10-27 12:28:30

标签: javascript node.js json http-post

我的网址是这样的:

https://hooks.zapier.com/hooks/catch/2020200/jasoa43

我的代码是什么?如何获取端口,路径将如何?请检查以下代码,让我知道这些参数是什么。

const https = require('https')

        const data = 'data'
     
        const options = {
            hostname: ??,
            port: ??,
            path: ??,
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Content-Length': data.length
            }
        }

        const req = https.request(options, res => {
            console.log(`statusCode: ${res.statusCode}`)

            res.on('data', d => {
                process.stdout.write(d)
            })
        })

        req.on('error', error => {
            console.error(error)
        })

        req.write(data)
        req.end()

1 个答案:

答案 0 :(得分:0)

 const https = require('https')

        const data = JSON.stringify({
         
            pin:change.after.data().pin,
            name:change.after.data().firstName,
            email:change.after.data().email,
            phone:change.after.data().phone,

        });
     
        const options = {
            hostname: 'hooks.zapier.com',
            port: 443,
            path: '/hooks/catch/5977644/ofrda44',
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Content-Length': data.length
            }
        }

        const req = https.request(options, res => {
            console.log(`statusCode: ${res.statusCode}`)

            res.on('data', d => {
                process.stdout.write(d)
            })
        })

        req.on('error', error => {
            console.error(error)
        })

        req.write(data)
        req.end()