socket problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amolkad
Forum Newbie
Posts: 22
Joined: Tue Jun 01, 2004 7:22 am

socket problem

Post 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);
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
amolkad
Forum Newbie
Posts: 22
Joined: Tue Jun 01, 2004 7:22 am

Post by amolkad »

Thanks Weirdan,

Is there any way to post request to HTTPS port via sockets?Because Curl may not enabled on server.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
amolkad
Forum Newbie
Posts: 22
Joined: Tue Jun 01, 2004 7:22 am

Post by amolkad »

Thanks a lot Weirdan.
Post Reply