要使用 mandrill api 发送交易电子邮件,我正在使用这个 mandrill api -
https://mandrillapp.com/api/1.0/messages/send.json
我正在尝试将此 JSON 数据(有效负载)发布到它 -
{
'key' : 'MyActualKey',
'message': {
'html': '<p>Example HTML content</p>',
'text': 'Example text content',
'subject': 'example subject',
'from_email': 'from@example.com',
'from_name': 'Test',
'to': [
{
'email': 'to@example.com',
'name': 'Hussain',
'type': 'to'
}
],
'headers': {
'Reply-To': 'reply@example.com'
},
'merge': True,
'tags': [
'Mandrill Test'
]
},
'ip_pool': 'Main Pool'
}
所以当我执行这个 curl 命令时 -
curl -X POST -H "Content-Type: application/json" --data @TestMandrillPayload.json https://mandrillapp.com/api/1.0/messages/send.json -v
我收到这个错误 -
* About to connect() to proxy 127.0.0.1 port 8000 (#0)
* Trying 127.0.0.1... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
但是当我在这里使用相同的 json 时 -
https://mandrillapp.com/api/docs/messages.JSON.html#method-send
邮件发送成功。
我尝试在互联网上搜索此问题的原因,每个人都认为我的 DNS 或防火墙有问题。它出什么问题了?
最佳答案
如果是 DNS 问题,则对域 mandrillapp.com
执行 ping 操作并获取 IP 并将其用于您的 curl。
如果您有不同的 DNS 服务器 IP 地址,那么您也可以使用 curl 命令指定它。
--dns-servers IP
此外,将 -k
命令行参数与 curl 命令一起使用。
关于post - 调用 mandrill api 时连接拒绝 curl 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21780365/