食尸鬼的form_params不接受数组 [英] Guzzle form_params not accepting array
本文介绍了食尸鬼的form_params不接受数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Guzzle 6,并且无法在客户端主体中传递带有form_params的数组
I am using Guzzle 6 and I can't pass array with form_params in the body of the client
$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]);
最后,当我发送请求时,我的数据不见了……但是,如果我在响应中手动添加数据,它就可以正常工作.
Finally, when i send the request my data is gone... But if I manually add the the data in the response it's working fine.
$response = $client->post(
'api',
[form_params => [
'data[test]'=>"TEST",
'data[wht]' => 'Whatever'
],
]
// It's working this way...
我希望我很清楚是否需要更多信息.预先感谢.
I hope I am clear enough if u need more info feel free to ask. Thanks in advance.
推荐答案
我看到了几个问题.首先是您的 $ postFields
数组似乎没有正确格式化的事实,其次是将$ postFields数组包装在另一个数组中.
I see a couple of issues. First is the fact that your $postFields
array does not appear to be properly formatted, and second you wrap your $postFields array inside another array.
$options = [
'debug' => true,
'form_params' => [
'test' => 15,
'id' => 43252435243654352,
'name' => 'this is a random name',
],
'on_stats' => $someCallableItem,
];
$response = $client->post('api', $options);
这篇关于食尸鬼的form_params不接受数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文