我遵循NodeJS Twilio SDK文档,提供以下内容:
const twilio = require('twilio')
exports.sendActivationCode = async (phone, activationCode) => {
const accountSID = '<REDACTED>'
const authToken = '<REDACTED>'
const client = twilio(accountSID, authToken)
return await client.messages.create({
body: `Your activation code is ${activationCode}`,
from: '+1<REDACTED>',
to: `+1${phone.toString().replace(/\D/g, '')}`
})
}我已经检查了很多次,以确保我与文档直接匹配。当我尝试运行代码时,我得到了Error: Headers User-Agent forbidden。请求本身显示头部正在传出:'User-Agent': 'twilio-node/3.45.0 (node.js v10.15.3)',堆栈输出表明它来自jsdom -> xhr-utils。
发布于 2020-06-30 10:59:57
这就是为我修复它的方法。只需将以下内容添加到您的package.json文件中。
"jest": {
"testEnvironment": "node"
},https://stackoverflow.com/questions/62265206
复制相似问题