Guzzle参数多数组
Guzzle parameters multiple array
我有卷曲请求:
curl http://example.com/json/get_products_by_multifilter -d '{"multifilter":{"limit":5}}'
我的 Guzzle 代码:
$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();
我收到错误:
[InvalidArgumentException]
没有方法可以处理多过滤器配置键
我的代码有什么问题,如何将多个数组作为参数?
在 Guzzle 5 中,您需要在密钥 body
中提供 post 数据
查看文档以获取更多信息:http://guzzle.readthedocs.org/en/latest/clients.html
使用 post 方法的示例:
$client->post('http://example.com/json/get_products_by_multifilter', [
'body' => [
'multifilter' => ['limit' => 1]
]
]);
使用createRequest
$request = $client->createRequest(
'POST',
'http://example.com/json/get_products_by_multifilter',
['body' => 'multifilter' => ['limit' => 1]]
);
每次看到错误时
[InvalidArgumentException] No method can handle the multifilter config
key
表示您在选项中使用的密钥不存在,guzzle不知道如何处理。
我有卷曲请求:
curl http://example.com/json/get_products_by_multifilter -d '{"multifilter":{"limit":5}}'
我的 Guzzle 代码:
$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();
我收到错误:
[InvalidArgumentException]
没有方法可以处理多过滤器配置键
我的代码有什么问题,如何将多个数组作为参数?
在 Guzzle 5 中,您需要在密钥 body
中提供 post 数据查看文档以获取更多信息:http://guzzle.readthedocs.org/en/latest/clients.html
使用 post 方法的示例:
$client->post('http://example.com/json/get_products_by_multifilter', [
'body' => [
'multifilter' => ['limit' => 1]
]
]);
使用createRequest
$request = $client->createRequest(
'POST',
'http://example.com/json/get_products_by_multifilter',
['body' => 'multifilter' => ['limit' => 1]]
);
每次看到错误时
[InvalidArgumentException] No method can handle the multifilter config key
表示您在选项中使用的密钥不存在,guzzle不知道如何处理。