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,$err str,30);
if(!$sock)
die("$errstr ($errno)\n");
fwrite($sock,"GET /theGetPath?valOne=1&valTw o=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
Here's my code
------------------
<?
error_reporting (E_ALL);
$sock = fsockopen("secure.example.
if(!$sock)
die("$errstr ($errno)\n");
fwrite($sock,"GET /theGetPath?valOne=1&valTw
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
Try echoing/printing your $headers and $body variables ;)
ASKER
I solved the problem. I used cURL to make the connection and everything works fine.
Tx,
bmh
Tx,
bmh
As always - ask for refund in community support area. =)
https://www.experts-exchange.com/help.jsp#hi70
https://www.experts-exchange.com/help.jsp#hi70
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER