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

时间:2017-12-16 21:32:41

标签: php post guzzle

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

$fruits = ['apple', 'orange', 'banana'];
$client   = new \GuzzleHttp\Client();
$response = $client->post('http://example/post', [ 
   'form_params' => [ 'fruits' => $fruits ] 
] );

1 个答案:

答案 0 :(得分: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
        ]);