Problems POSTing an array to a custom web service...???

I've got a little custom web service I'm trying to build to make things a little easier on myself within another project.  I've got a simple CURL function setup to POST data to my own web service....


function CallService($EndPointURL, $PostData)
{
      $curl = curl_init();
                  curl_setopt($curl, CURLOPT_VERBOSE, 1);
                  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
                  curl_setopt($curl, CURLOPT_TIMEOUT, 120);
                  curl_setopt($curl, CURLOPT_URL, $EndPointURL);
                  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt($curl, CURLOPT_POSTFIELDS, $PostData);      
      $response = curl_exec($curl);
      curl_close($curl);
      return $response;
}



So then here's a sample of what I'm setting up to use it with...



$Payments = array();
$Receiver = array('ReceiverEmail' => 'sandbo_1215254764_biz@angelleye.com','Amount' => '7.50');
$Receiver2 = array('ReceiverEmail' => 'tester_1267304351_biz@angelleye.com','Amount' => '7.50');
array_push($Payments,$Receiver);
array_push($Payments,$Receiver2);

$PostData = array(
                              'SenderID' => '',
                              'SenderEmail' => 'sandbo_1204199080_biz@angelleye.com',
                              'Payments' => $Payments
                        );
                        
$GetPayKeyResponse = CallService($domain.'/angelleye/paypal/web-services/get-pay-key.php',$PostData);



If I dumpt out my $PostData array on the calling script I get exactly what I expect...



Array
(
    [SenderID] =>
    [SenderEmail] => sandbo_1204199080_biz@angelleye.com
    [Payments] => Array
        (
            [0] => Array
                (
                    [ReceiverEmail] => sandbo_1215254764_biz@angelleye.com
                    [Amount] => 7.50
                )

            [1] => Array
                (
                    [ReceiverEmail] => tester_1267304351_biz@angelleye.com
                    [Amount] => 7.50
                )

        )

)


But when I go ahead and pass it to my web service it's losing the Payments array data somehow.  Right now I've got my service setup to do the following...



$Payments = isset($_POST['Payments']) ? $_POST['Payments'] : array();



echo '<pre />';

print_r($Payments);

exit();



So then in my calling script I simply echo out the response I get back from the service, but I wind up with what you see at this URL...

http://drinkgifter.developersandbox.net/angelleye/paypal/button-service.php

It simply outputs the word Array instead of any actual contents of an array.  

So I'm a little bit lost why that's happening.  I always thought I could POST array values just like any other value..??  My text values are going over just fine, but my array ends up as just "Array" and I can't loop through it or anything.

Any information on what I'm doing wrong here would be greatly appreciated.  Thanks!

LVL 11
Andrew AngellCo-Owner / DeveloperAsked:
Who is Participating?
 
Rik-LeggerConnect With a Mentor Commented:
You could serialize() the array before posting it with cUrl.
Then you can unserialize it when you want to use it:

$PostData = array(
                              'SenderID' => '',
                              'SenderEmail' => 'sandbo_1204199080_biz@angelleye.com',
                              'Payments' => serialize($Payments)
                        );

...

$Payments = isset($_POST['Payments']) ? $_POST['Payments'] : array();



echo '<pre />';

print_r(unserialize($Payments));

exit();
0
 
Andrew AngellCo-Owner / DeveloperAuthor Commented:
Doh!  Forgot all about serialize().  Works perfectly.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.