[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2011-04-20
Medium Priority
Last Modified: 2012-05-11
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);
      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');

$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...

    [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 />';



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...


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!

Question by:Andrew Angell

Accepted Solution

Rik-Legger earned 2000 total points
ID: 35435862
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 />';


LVL 11

Author Comment

by:Andrew Angell
ID: 35436178
Doh!  Forgot all about serialize().  Works perfectly.  Thanks!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month20 days, 1 hour left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question