相关疑难解决方法(0)

使用PHP和CURL发布多维数组

我无法通过CURL将表单数据发布到位于不同主机上的接收PHP脚本.

我收到一个Array to string conversion错误

这是print_r我发布的数组:

Array
(
    [name] => Array
    (
        [0] => Jason
        [1] => Mary
        [2] => Lucy
    )
    [id] => 12
    [status] => local
    [file] => @/test.txt
)
Run Code Online (Sandbox Code Playgroud)

这是错误发生的行:

curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post);
Run Code Online (Sandbox Code Playgroud)

第三个参数必须是一个数组,因为我需要将Content-Type头设置multipart/form-data为我通过同一个数组发送文件,因此我无法将数组转换为查询字符串或使用http_build_query().

此外,我无法访问接收主机上的代码,因此我无法序列化和反序列化数组.

我假设名称键的值是一个数组是导致此错误的原因,我也假设CURLOPT_POSTFIELDS不支持多维数组.有没有其他方法可以解决这个问题,还是我注定要失败?

提前致谢!

php arrays post curl

43
推荐指数
5
解决办法
5万
查看次数

标签 统计

arrays ×1

curl ×1

php ×1

post ×1