I am writing a program that uses cURL to access an UPS API. The problem I am running into is that I keep getting return of bool(false) doing a var_dump on curl_exec();
Can you see if I am passing the information correctly using POST?
I've done a few other API's w/ UPS but this is the first time I've tried using POST w/ TLS1.2. For TLS1.2 I have the CURL_SSLVERSION, 6.
I appreciate any insight. Thanks.
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
//credentials
$accessKey = "abc123";
$user = "abc";
$pass = "123";
$targetDIR = '/abc/123/xyz';
$port = '443';
$url = 'https://www.pld-certify.ups.com'.$targetDIR.'';
$postFields = array('AppVersion' => '1.0',
'AcceptUPSLicenseAgreement' => 'Yes',
'ResponseType' => 'application/x-ups-pld',
'VersionNumber' => 'V4R1',
'UserId' => $user,
'Password' => $pass
);
//create URL out of post
$fieldString = NULL;
foreach($postFields as $a=>$b){
$fieldString .= $a . '=' . $b . '&';
}
$fieldString = rtrim($fieldString, '&');
$body = '--BOUNDARY
Content-type: application/x-ups-binary
Content-length: 719
020094 2011R0 2014093000000012939600400909000000001*AA111111 US0 0129396004000001*BA1Z1111110300002095 00001+0000000000000070 +0000000000000000LBS03PRE10 3INUSD000001*CA18TEST ORDER TEST ORDER 10800 E 45TH AVE DENVER CO 80239 US15555555555 *PA1Z1111110300002095 02+0000070 +0000000+00000000+00000000+00000000*SA000004
--BOUNDARY--';
$header[] = "Host: www.pld-certify.ups.com";
$header[] = "MIME-Version: 1.0";
$header[] = "Content-type: multipart/mixed; boundary=BOUNDARY";
$header[] = "Content-length: ".strlen($body);
$header[] = "Cache-Control: no-cache";
$header[] = "Connection: close \r\n";
$header[] = $body;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($postFields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
?>