我试图在节点中放入一个 curl 命令,我必须使用 Mailgun API 进行电子邮件验证,但是当我发出请求时,api 永远不会像 curl 那样识别“地址”字段。
以下是脚本和结果:
卷曲命令
curl -s --user api:pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7 -G \
https://api.mailgun.net/v2/address/validate \
-d address='john.smith@gmail.com'
Node.js 脚本
var request = require('request')
, inspect = require('util').inspect
var options = {
url: 'https://api.mailgun.net/v2/address/validate'
, method: 'GET'
, encoding: 'ASCII'
// , body: "address=john.smith@gmail.com"
, form: { address: "john.smith@gmail.com" }
, auth: {
username: "api"
, password: "pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7"
}
}
request(options, function (err, result){
if(err){ console.log(err) }
console.log(inspect(result.request.body.toString('utf8')))
console.log(inspect(result.request.response.body))
})
预期产出
{
"is_valid": true,
"parts": {
"local_part": "johnsmith",
"domain": "gmail.com",
"display_name": null
},
"address": "john.smith@gmail.com",
"did_you_mean": null
}
我得到的输出
'address=john.smith%40gmail.com'
'{\n "message": "Missing parameter: address"\n}'