using curl for https connection
Posted: Thu Nov 15, 2007 3:07 pm
I am trying unsuccessfully to send an xml request and receive an xml response from the UPS server to calculate shipping costs for a shopping cart I am building. I can curl http sites fine, but not https sites.
When I try this code on https sites I always get a connection timed out message with no other info. Am I missing something? Do I need to set some curl option to tell it to use port 443? I am new to curl and I am totally lost. I have trouble connecting regardless of whether I am sending straight xml or a string variable.
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, "licksick:lsbforever");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// execute
$ret = curl_exec($ch);
if (empty($ret)) {
// some kind of an error happened
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'];
}
}Any help would be greatly appreciated!I am using:
php 5.1.4
libcurl 7.10.6
openssl 0.9.7a