You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel调用Smartrmail新增订阅者接口报subscribers参数缺失错误问询

问题原因

  • 请求头声明了Content-Type: application/json,但Guzzle请求中使用了form_params参数,form_params仅用于发送x-www-form-urlencoded格式的表单数据,和声明的请求格式不匹配,发送JSON格式数据需要使用Guzzle的json参数。
  • 已经包含subscribers键的$data被额外套了一层数组,最终发送的参数结构变成了[0 => ['subscribers' => [...]]],服务端无法读取到顶层的subscribers参数,因此报参数缺失错误。

修复后代码

Route::get('smartrmail',function(){
    $headers = [
        'Accept' => 'application/json',
        'Authorization' => 'token f91715d5-3aac-4db3-a133-4b3a9493a9a4',
    ];
    
    $client = new GuzzleHttp\Client([
        'headers' => $headers
    ]);
    $data = [
        "subscribers"=>[
            [
                "email"=> "vanhalen@example.com",
                "first_name"=> "van",
                "last_name"=> "halen",
                "subscribed"=> true,
            ]
        ]
    ];
    $res = $client->request('POST', 'https://go.smartrmail.com/api/v1/lists/1sptso/list_subscribers', [
        'json' => $data
    ]);
    return $res;
});

内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 04:48:01