how can the package “https” be used to send a POST Call but with urlencoded body? I can’t use any package other than https
“data” needs to be URL encoded, since the target Endpoint expects it
….
const options = {
agent,
hostname: “myTestURL.com”,
port: 443,
path: ‘/foo’,
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/x-www-form-urlencoded’,
},
}
let response = ''
const req = https.request(options, (res) => {
res.on('data', (d) => {
response += d
})
})
req.on('error', (e) => {
console.error(e)
})
req.write(new URLSearchParams(data))
req.end()
New contributor
Marcel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.