I need to send a POST request via PHP cURL. It needs to include both a file and an array parameter. The raw curl command should look like this:
curl "https://the.url.com"
-F file="@/path/to/file.xml"
-F 'list_item[]=foo'
-F 'list_item[]=bar'
Unfortunately the list_item[] parameter cannot have keys (i.e. list_item[0], list_item[1], etc...) otherwise the server throws an error.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://the.url.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'file' => curl_file_create($file),
'list_item' => [
'foo',
'bar'
]
]);
$response = curl_exec($ch);
This must be producing the wrong curl command because it's also being rejected.
Can anyone help?