Jump to content

Sending array within array in PHP cURL CURLOPT_POSTFIELDS


isfak

Recommended Posts

Hello!

 

I am trying to download a CSV file with the following curl:

$arrPostData = array(
'task' => 'download',
'selectedFields' => array('1', '2', '3') );

curl_setopt($ch, CURLOPT_URL, $strURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($arrPostData));
$strCurlDownload = curl_exec($ch);

This curl unfortunately does not produce anything (nor fails with curl_errno).

Then I modify the $arrPostData array like that:

$arrPostData = array(
'task' => 'download',
'selectedFields' =>'1');

This works, but then I only get field 1 in the output CSV file. How can I modify the curl to be able to get all fields 1,2,3?

 

Thanks!

Edited by isfak
Link to comment
Share on other sites

How does the service expect to receive multiple values of selectedFields? If it's not PHP style as "selectedFields[]=" then it's probably the more traditional style of using multiple "selectedFields=", which you'd have to build by-hand as PHP doesn't have a native function to do it for you.

curl_setopt($ch, CURLOPT_POSTFIELDS, "task=download&selectedFields=1&selectedFields=2&selectedFields=3");
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.