你如何用Guzzle发布数组字段?

问题描述 投票:1回答:1

你如何用Guzzle发布数组字段?我尝试了以下但是在fruits变量中没有收到任何内容。

$fruits = ['apple', 'orange', 'banana'];
$client   = new \GuzzleHttp\Client();
$response = $client->post('http://example/post', [ 
   'form_params' => [ 'fruits' => $fruits ] 
] );
php post guzzle
1个回答
0
投票

你可以试试这个

$fruits = ['apple', 'orange', 'banana'];

$client  = new \GuzzleHttp\Client();

$response = $client->request('POST', http://example/post, [
            'headers' => [
                'Content-Type' => 'application/x-www-form-urlencoded'
            ],
            'form_params' => $fruits
        ]);
© www.soinside.com 2019 - 2024. All rights reserved.