Guzzle form_params 不接受数组
Guzzle form_params not accepting array
我正在使用 Guzzle 6,我无法在客户端的正文中传递带有 form_params 的数组
$postFields = [
form_params => [
'data[test]' => "TEST",
'data[whatever]' => "Whatever..."
]
];
$client = new GuzzleClient([
'cookies' => $jar, // The cookie
'allow_redirects' => true, // Max 5 Redirects
'base_uri' => $this->navigateUrl, // Base Uri
'headers' => $this->headers
]);
$response = $client->post('api',[$postFields]);
最后,当我发送请求时,我的数据消失了...但是如果我在响应中手动添加数据,它就可以正常工作。
$response = $client->post(
'api',
[form_params => [
'data[test]'=>"TEST",
'data[wht]' => 'Whatever'
],
]
// It's working this way...
我希望我足够清楚,如果您需要更多信息,请随时询问。提前致谢。
我发现了几个问题。首先是您的 $postFields
数组似乎格式不正确,其次您将 $postFields 数组包装在另一个数组中。
$options = [
'debug' => true,
'form_params' => [
'test' => 15,
'id' => 43252435243654352,
'name' => 'this is a random name',
],
'on_stats' => $someCallableItem,
];
$response = $client->post('api', $options);
我正在使用 Guzzle 6,我无法在客户端的正文中传递带有 form_params 的数组
$postFields = [
form_params => [
'data[test]' => "TEST",
'data[whatever]' => "Whatever..."
]
];
$client = new GuzzleClient([
'cookies' => $jar, // The cookie
'allow_redirects' => true, // Max 5 Redirects
'base_uri' => $this->navigateUrl, // Base Uri
'headers' => $this->headers
]);
$response = $client->post('api',[$postFields]);
最后,当我发送请求时,我的数据消失了...但是如果我在响应中手动添加数据,它就可以正常工作。
$response = $client->post(
'api',
[form_params => [
'data[test]'=>"TEST",
'data[wht]' => 'Whatever'
],
]
// It's working this way...
我希望我足够清楚,如果您需要更多信息,请随时询问。提前致谢。
我发现了几个问题。首先是您的 $postFields
数组似乎格式不正确,其次您将 $postFields 数组包装在另一个数组中。
$options = [
'debug' => true,
'form_params' => [
'test' => 15,
'id' => 43252435243654352,
'name' => 'this is a random name',
],
'on_stats' => $someCallableItem,
];
$response = $client->post('api', $options);