Link to home
Start Free TrialLog in
Avatar of bmh777
bmh777

asked on

Making a socket connection using HTTPS

I'm trying to make a socket connection using HTTPS.

Here's my code
------------------
<?
error_reporting (E_ALL);

$sock = fsockopen("secure.example.com",443,$errno,$errstr,30);

if(!$sock)
  die("$errstr ($errno)\n");

fwrite($sock,"GET /theGetPath?valOne=1&valTwo=2 HTTP/1.0\r\n");
fwrite($sock,"Host: secure.example.com\r\n");
fwrite($sock,"Connection: close\r\n\r\n");

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

echo "\n";

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

fclose($sock);
?>

My browser gives me a completely blank screen - no errors or anything.  Are my headers incorrect?  Am I missing a neccessary header?  I know this is a secure protocol, so do I need to include any particular headers because of that?

I've also tried to do this using a output buffering, but I can't figure out how to access the resulting HTML after sending the initiate URL to the server.

How can I do this using either fsoockopen( ) or ob_start( )?

Tx,
bmh
Avatar of bmh777
bmh777

ASKER

I REALLY need help with this.  Anyone?
Try echoing/printing your $headers and $body variables ;)
Avatar of bmh777

ASKER

I solved the problem.  I used cURL to make the connection and everything works fine.

Tx,
bmh
As always - ask for refund in community support area. =)
https://www.experts-exchange.com/help.jsp#hi70
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial