0

I am making an application that deals with postbacks, and I wanted to make it so it would be able to postback to domains with https:// even if the person who is using the app doesn't have the openssl php extension. (It would warn them that their postbacks would be made non securely.)

I turned off openssl and tried the following, but it is giving me an error that I do not have https wrapper.

$arrContextOptions=array(
  "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);
echo file_get_contents('https://httpbin.org/get?test=test', true, stream_context_create($arrContextOptions) );

Is it possible to make this request with file_get_contents?

scorgn
  • 3,439
  • 2
  • 20
  • 23
  • possible duplicate [file_get_contents(): SSL operation failed with code 1. And more](http://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-and-more) – Amr Aly Mar 09 '17 at 17:32
  • I came across this question previously and as you can see my code directly matches the accepted answer. – scorgn Mar 09 '17 at 18:42
  • No it does not match the accepted answer there the second param was set to `false` but in your answer is `true` – Amr Aly Mar 09 '17 at 18:52
  • You are right. Unfortunately neither would work in my situation. – scorgn Mar 09 '17 at 19:04

1 Answers1

-1

Try this code:

<?php
$fp = fsockopen("ssl://somedomain/abc/", 2000 , $ErrNo, $ErrString, 30);
if (!$fp) {
    echo "Error No : $ErrNo - $ErrString <br />\n";
} else {
    $out  = "POST / HTTP/1.1\r\n";
    $out .= "Host: somedomain \r\n";
    $out .= "Content-Type: application/xml; charset=utf-8;\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}
?>

I have research file_get_contents with --no-check-certificate

readmore here file_get_contents ignoring verify_peer=>false?

Community
  • 1
  • 1
HoangHieu
  • 2,802
  • 3
  • 28
  • 44