【问题标题】:Guzzle form_params not accepting arrayGuzzle form_params 不接受数组
【发布时间】:2015-11-27 01:52:16
【问题描述】:

我正在使用 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...

如果您需要更多信息,请随时询问。提前致谢。

【问题讨论】:

    标签: php guzzle guzzle6


    【解决方案1】:

    我看到了几个问题。首先是您的 $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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      • 2019-04-14
      • 2020-12-09
      • 2015-05-26
      相关资源
      最近更新 更多