如何在php中为curl post构建一个数组而不覆盖上一个字段?标题在帖子中显示了以下内容:
Content-Disposition: form-data; name="price[][unit]"
One
-----------------------------122371200014463
Content-Disposition: form-data; name="price[][price]"
50
-----------------------------122371200014463
Content-Disposition: form-data; name="price[][unit]"
Two
-----------------------------122371200014463
Content-Disposition: form-data; name="price[][price]"
95
-----------------------------122371200014463
Content-Disposition: form-data; name="price[][unit]"
Three
-----------------------------122371200014463
Content-Disposition: form-data; name="price[][price]"
140
当我试图构建这样的数组时,我一直覆盖前面的项目:
$postPrice['price[][unit]'] = 'One';
$postPrice['price[][price]'] = $one;
$postPrice['price[][unit]'] = 'Two';
$postPrice['price[][price]'] = $two;
$postPrice['price[][unit]'] = 'Three';
$postPrice['price[][price]'] = $three;
您可以尝试:
$fields = array(
'price[][unit]' => "One",
'price[][price]' => $one
)
);
$fields_string = http_build_query($fields);
然后:
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);