Page 1 of 1

socket problem

Posted: Tue Jun 01, 2004 7:22 am
by amolkad
I am using following code to send request through the socket.The server
is https://secure.example.com. The request get send but response i am getting is encrypted some thing like([] [] [] []). I am not getting problem.
help me.

$book_flight='has some xml data';

$sock = fsockopen("secure.examle.com", 8443, $errno, $errstr);
if (!$sock) die("$errstr ($errno)\n");


fwrite($sock, "POST /example/FltConfirmRequest HTTPS/1.0\r\n");
fwrite($sock, "Host: secure.example.com");
fwrite($sock, "Content-type: text/xml\r\n");
fwrite($sock, "Content-length: " . strlen($book_flight) . "\r\n");
fwrite($sock, "Accept: */*\r\n");
fwrite($sock, "\r\n");
fwrite($sock, $book_flight);
fwrite($sock, "\r\n");

$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n";
echo "\n";

$body = "";
while (!feof($sock))
$body .= fgets($sock, 4096);

fclose($sock);

Posted: Tue Jun 01, 2004 8:00 am
by Weirdan
You shouldn't make HTTP requests to HTTPS port. In case you need to POST data over encrypted channel use [php_man]cURL[/php_man] extension.

Posted: Tue Jun 01, 2004 11:46 pm
by amolkad
Thanks Weirdan,

Is there any way to post request to HTTPS port via sockets?Because Curl may not enabled on server.

Posted: Wed Jun 02, 2004 12:20 am
by Weirdan
You always should have some special configuration on your host to support HTTPS interaction. At least you need SSL library, which, of course, may not be installed on target system. So, there is no absolutely portable way. And cURL seems reasonable requirement IMO since it widely used.

Keep in mind, even if you have cURL installed it may either have HTTPS support or not, depending on compile options.

Posted: Wed Jun 02, 2004 5:01 am
by amolkad
Thanks a lot Weirdan.