Hi all.
I have been quite frustrated with this problem and would appreciate any help.
I'm working on an API and I have a working version and a non-working version, but I can't tell what the problem is on the non-working version...
WORKING SCRIPT::
<?php
$sitename = 'howitworks';
$inputdata = 'apiaction=SITENAMELOOKUP&datatype=DELIMITED&delimiter_1==&delimiter_2=;&live=N&cl=XXX&lc=XXXXX&api=XXXXX&FORCE_GET=Y&sitename='.$sitename;
$x = curl_init("https://example.com/api_call.asp?".$inputdata);
curl_setopt($x, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($x, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($x, CURLOPT_HEADER, 1);
curl_setopt($x, CURLOPT_POST, 1);
curl_setopt($x, CURLOPT_POSTFIELDS, $inputdata);
curl_setopt($x, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);
if (curl_exec($x) === false)
{
echo 'Curl error: ' . curl_error($x);
}else{
$data = curl_exec($x);
curl_close($x);
}
echo"$data<br><br>";
echo"***exploded***<br><br>";
$data=explode(";", $data);
var_dump($data);
?>
NON-WORKING SCRIPT
<?php
foreach($_POST as $key => $val){$$key = $val;}
$inputdata='APIACTION=SIGNUPORDER&ALT_ACT='.$alt_act.'&datatype=DELIMITED&delimiter_1==&delimiter_2=;&live=N&cl=XXX&lc=XXXXX&api=XXXXX&firstname='.$firstname.'&lastname='.$lastname.'&sitename='.$sitename.'&phone='.$phone.'&email='.$email.'&mb_phone='.$mb_phone.'&address1='.$address1.'&city='.$city.'&state='.$state.'&zip='.$zip.'&country='.$country.'&phy_address1='.$phy_address1.'&phy_city='.$phy_city.'&phy_state='.$phy_state.'&phy_zip='.$phy_zip.'&phy_country='.$phy_country.'&ssn='.$ssn.'&dob='.$dob.'&status='.$status.'&e2a_pass='.$e2a_pass.'&sec_ques='.$sec_ques.'&sec_answ='.$sec_answ.'&sponsor='.$sponsor.'&enroller='.$enroller.'&FORCE_GET=Y';
$x = curl_init("https://example.com/api_call.asp?".$inputdata);
curl_setopt($x, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($x, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($x, CURLOPT_HEADER, 1);
curl_setopt($x, CURLOPT_POST, 1);
curl_setopt($x, CURLOPT_POSTFIELDS, $inputdata);
curl_setopt($x, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);
if (curl_exec($x) === false)
{
echo 'Curl error: ' . curl_error($x);
}else{
$data = curl_exec($x);
curl_close($x);
}
echo"$data<br><br>";
echo"***exploded***<br><br>";
$data=explode(";", $data);
var_dump($data);
?>
Things I know:
Curl was choking on the SSL cert where I'm attempting to send data - curl_setopt($x, CURLOPT_SSL_VERIFYPEER, FALSE); fixed this.
Neither were sending variables, but rather the literal "$variable_name" until I started concatenating.
Neither were actually posting values - workaround ok by passing FORCE_GET=Y
curl_setopt($x, CURLOPT_VERBOSE, 1); seems to do nothing - won't show what curl is attempting to do or where I'm losing data...
if I...
echo "https://example.com/api_call.asp?".$inputdata
...and copy/paste into my browser, the api call is successful.
WHAT I SUSPECT, BUT CAN'T PROVE...
Some variables (ssn, dob, etc.) may have special characters and some variables (address, secret question, etc.) may have spaces. I have tried $inputdata=urlencode($inputdata) before the curl, but no luck. Pasting that result (with the urlencoded stuff) directly into the address bar fails (returns "bad request" from the api.
THE QUESTION:
How can I see exactly what curl is trying to post before/during?
How can I see that URL it's trying to open before/during?
Why does curl_setopt($x, CURLOPT_VERBOSE, 1); not show me these things?
Have I missed something simple?
Thanks in advance.