【问题标题】:How to send array of string Guzzle如何发送字符串数组 Guzzle
【发布时间】:2020-05-02 21:49:47
【问题描述】:

我想在这段代码中将 include_players_ids[] 值替换为多个玩家 ID 的数组。我试过身体,但它说不推荐使用。请提供任何帮助。 Guzzle 版本是 6。我试过 ['id', 'id'] 和 array('id', 'id')。响应是“include_player_ids”应该是一个数组或格式错误

$client = new Client();
    try {

        $r = $client->request('POST', 'https://onesignal.com/api/v1/notifications', [

            'form_params' =>
                [

                'app_id' => 'app_id',

                'include_player_ids[]' => '9cc7691d-04ea-4245-9eed-667f70a218c1',

                'headings' => [
                    'en' => $request->input('title')
                ]
            ]
        ]);

【问题讨论】:

    标签: php laravel guzzle6


    【解决方案1】:

    你可以试试:

    'form_params' =>
                    [
    
                    'app_id' => 'app_id',
    
                    'include_player_ids' => ['9cc7691d-04ea-4245-9eed-667f70a218c1', 'dummy']
    
                    'headings' => [
                        'en' => $request->input('title')
                    ]
                ]
    

    http://docs.guzzlephp.org/en/stable/request-options.html#form-params

    【讨论】:

    • 谢谢。我已经尝试过了,但一个信号说“include_player_ids 应该是一个数组”
    • 我不明白你的目的
    • 'include_player_ids' 是一个数组,因此@NguyenHungThai 已正确声明该数组。此代码现在不应给出相同的错误。
    猜你喜欢
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    相关资源
    最近更新 更多