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

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.

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

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题