【问题标题】:Laravel + Guzzle + MailChimp - 400 Bad RequestLaravel + Guzzle + MailChimp - 400 错误请求
【发布时间】:2017-04-10 03:46:24
【问题描述】:

我在执行 Guzzle 请求时收到 400 Bad Request,这是我第一次使用 Laravel、Guzzle 和 Mailchimp,所以我差点咬断手指。我不明白我在这个问题上做错了什么。有人可以帮帮我吗?

$mailchimp = new Client(['base_uri' => 'https://us14.api.mailchimp.com/3.0/']);

$checkEmail = $mailchimp->request('POST', 'lists/ID/members/', [
        'headers' => [ 'Authorization' => 'apikey ' . config('globals.mailchimp_key') ],
        'json' => [
            'email_address' => $this->email,
            'status' => 'subscribed'
        ]
    ]);
return $checkEmail;

【问题讨论】:

    标签: php laravel mailchimp guzzle mailchimp-api-v3.0


    【解决方案1】:

    我认为您的标题格式不正确(请参阅docs)。 不如试试这种方式:

                $client = new \GuzzleHttp\Client();
                $res = $client->request('POST',       'https://us8.api.mailchimp.com/3.0/lists/6f0984e55f/members/', [
                'auth' => ['apikey', 'xxxxxxxxxxxxxx-us14'],
                    'json' => [
                        'email_address' => 'example@example.com',
                        'status' => 'subscribed'
                    ]
            ]);
            echo $res->getStatusCode();
            echo $res->getBody();  
    

    【讨论】:

    • 不起作用,得到了相同的结果。当我想检索数据时,我的标题工作,所以我认为这不是问题
    猜你喜欢
    • 2016-11-18
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    • 2023-03-04
    • 2018-12-06
    • 2017-12-14
    • 2016-12-29
    • 1970-01-01
    相关资源
    最近更新 更多