【问题标题】:curl -d option with php for Sendgrid API用于 Sendgrid API 的带有 php 的 curl -d 选项
【发布时间】:2013-09-11 10:52:32
【问题描述】:

我在 sendgrid 邮件平台中找到了此选项,用于将多个电子邮件 ID 添加到列表中。就像:

curl -d 'api_user=your_sendgrid_username&api_key=your_sendgrid_password&list=my_list&data[]={"email":"address1@domain.com","name":"contactName1"}&data[]={"email":"address2@domain.com","name":"contactName2"}' https://sendgrid.com/api/newsletter/lists/email/add.json

现在我如何将它与 PHP curl 一起使用?

我对添加数据字段有疑问,并在某处读到 -d 是 POST 的开关。 但是对于sendgrid,几乎所有的api请求都是gets。

【问题讨论】:

    标签: php curl sendgrid


    【解决方案1】:

    -d 开关自动使用 POST 方法,所以如果你的 curl 命令有效,你可以使用 POST。要设置发布数据,您可以这样做:

    curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_user=your_sendgrid_username&...');
    

    或者要进行自动 urlencoding,使用数组

    curl_setopt($ch, CURLOPT_POSTFIELDS, array('api_user' => 'your_sendgrid_username' ...));
    

    【讨论】:

    • 谢谢兄弟。到处寻找这个答案。 :)
    猜你喜欢
    • 1970-01-01
    • 2021-12-16
    • 2014-09-20
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    相关资源
    最近更新 更多