duanjuan3931
duanjuan3931
2015-04-13 10:47
浏览 115
已采纳

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
    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.

    点赞 评论

相关推荐