Problem with fsockopen and SSL

From: Date: Mon, 09 Jan 2006 10:32:26 +0000
Subject: Problem with fsockopen and SSL
Groups: php.general 
Request: Send a blank email to php-general+get-228313@lists.php.net to get a copy of this message
Hi everyone! I want to connect to an SSL server but i can't get the content :( Here is the code i use: $xml = '<xml><data>Hello!</data></xml>'; function PostToHost($host, $path, $referer, $data_to_send) { $fp = fsockopen($host, 443); printf("Open!\n"); fputs($fp, "POST $path HTTP/1.1\r\n\r\n"); fputs($fp, "Host:$host\r\n"); fputs($fp, "Referer: $referer\r\n"); fputs($fp, "Content-type: text/xml\r\n"); fputs($fp, "Content-length: ". strlen($data_to_send) ."\r\n"); fputs($fp, "Connection: close\r\n"); //fputs($fp, $data_to_send); printf("Sent!\n"); while(!feof($fp)) {
      $res .= fgets($fp, 128);
} printf("Done!\n"); fclose($fp); return $res; } $data = $xml; printf("Go!\n"); $x = PostToHost(
              "ssl://easy-demo.tcinternet.de",
              "/hosting/servlet/Dispatcher",
              $GLOBALS["HTTP_REFERER"],
              $data
); echo $x; And this is what i get: Go! Open! Sent! Done! HTTP/1.1 400 Bad Request Date: Mon, 09 Jan 2006 10:28:48 GMT Server: Apache/2.0.53 (Unix) mod_ssl/2.0.53 OpenSSL/0.9.7e DAV/2 mod_jk/1.2.1 Content-Length: 363 Connection: close Content-Type: text/html; charset=iso-8859-1 Bad Request Your browser sent a request that this server could not understand. Apache/2.0.53 (Unix) mod_ssl/2.0.53 OpenSSL/0.9.7e DAV/2 mod_jk/1.2.1 Server at easy-demo.tcinternet.de Port 443 What did the Webserver not understood? Btw. i can't use cURL because the server has an old version of PHP (><)" Would be glad if you can help or even have a code how to connect to a SSL webserver via fsockopen that works. Btw the PHP version on server is: PHP Version 4.2.2 Thanks for any help! Greets Barry

« previous php.general (#228313) next »