xml request & response using php & curl

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
licksick
Forum Newbie
Posts: 6
Joined: Sat Nov 10, 2007 4:51 pm

xml request & response using php & curl

Post by licksick »

I am trying without any success to use curl to send/receive xml to the UPS server to calculate shipping costs for a shopping cart I am building.
I can use curl to access regular http urls, but not https urls. curl is new to me and I am totally lost.

Code: Select all

$ch = curl_init(); // create cURL handle (ch)
if (!$ch) {
    die("Couldn't initialize a cURL handle");
} else {
	echo 'curl handle initialized<br />';
}
// set some cURL options
$ret = curl_setopt($ch, CURLOPT_URL,            "https://wwwcie.ups.com/ups.app/xml/Rate");
$ret = curl_setopt($ch, CURLOPT_HEADER,         1);
$ret = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$ret = curl_setopt($ch, CURLOPT_TIMEOUT,        30);
$ret = curl_setopt($ch, CURLOPT_POSTFIELDS,		$xmlstr);

//   4 new lines trying to get https to work
$ret = curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,	false);
$ret = curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

// execute
$ret = curl_exec($ch);

if (empty($ret)) {
    echo '<br />some kind of an error happened<br />';
    die(curl_error($ch));
    curl_close($ch); // close cURL handler
} else {
    $info = curl_getinfo($ch);
    curl_close($ch); // close cURL handler

    if (empty($info['http_code'])) {
            die("No HTTP code was returned");
    } else {
        echo "The server responded: <br />";
        echo $info['http_code'];
    }
}
This code works for regular http sites but not https? For https sites I always get 'connection timed out' and no other error codes or info. Am I missing something? Do I have to tell curl to use port 443 or something?
Here is what I am working with:
php version 5.1.4
libcurl 7.10.6
openssl 0.9.7a
Any help would be really appreciated!
Post Reply