duanjuan3931 2015-04-13 10:47 采纳率: 0%
浏览 240
已采纳

Guzzle参数多个数组

I have curl request:

curl http://example.com/json/get_products_by_multifilter -d '{"multifilter":{"limit":5}}'

My Guzzle code:

    $client = new GuzzleHttp\Client();

    $request = $client->createRequest(
        'POST',
        'http://example.com/json/get_products_by_multifilter',
        array('multifilter' => array('limit' => 1))
    );
    $response = $client->send($request);

    echo $response->getBody();

I getting error:

[InvalidArgumentException]
No method can handle the multifilter config key

What is wrong with my code, how to mase multiple array as a parameters ?

  • 写回答

1条回答 默认 最新

  • dsw7547 2015-04-15 08:05
    关注

    In Guzzle 5 you need to provide the post data inside the key body

    Check the docs for more information: http://guzzle.readthedocs.org/en/latest/clients.html

    Example with post method:

    $client->post('http://example.com/json/get_products_by_multifilter', [
        'body' => [
            'multifilter' => ['limit' => 1]
        ]
    ]);
    

    With createRequest

    $request = $client->createRequest(
        'POST',
        'http://example.com/json/get_products_by_multifilter',
        ['body' => 'multifilter' => ['limit' => 1]]
    );
    

    Every time you see the error

    [InvalidArgumentException] No method can handle the multifilter config key

    Means that the key you are using in options does not exist and guzzle does not know how to handle it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?