What I'm trying to do overall is make a script that will connect to UPS Web Tools and get their shipping rates. I have to send an XML request to UPS and they will send an XML response back to me. What I am having a problem with right now is simply opening the connection to send the request.
The UPS doc says to connect using a secure HTTP connection, POST method, to port 443. Here is the code I have been messing with. This is just the connection code.
Code: Select all
// VALUES:
// $this->host = "www.ups.com"
// $this->path = "/ups.app/xml/Rate"
// $str is the XML request
// Generate the request header
$ReqHeader =
"POST ".$this->path." HTTP/1.1\r\n".
"Host: ".$this->host."\r\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"Content-Length: ".strlen($str)."\r\n\r\n";
// Open the connection to the host
$socket = fsockopen("https://".$this->host, 443, $errno, $errstr);
if (!$socket) {
$Resultї"errno"] = $errno;
$Resultї"errstr"] = $errstr;
return "<b>Connection Error $errno:</b> $errstr<br>\n";
}I don't have much experience with this so I don't know if there's something wrong with the code or the way I'm setting up the function. We don't have cURL installed on our server so I couldn't use cURL functions. (A lot of sample code for UPS rate finders had cURL functions.) I'm beginning to think that something might be wrong with our server that is preventing me from connecting, but I don't know enough about this to know what it would be or how to fix it.
If anyone has experience with this kind of connection, or with using the UPS Web Tools, I would greatly appreciate any advice you might have to offer. Thanks very much!