file_get_contents ignoring verify_peer=>false?

前端 未结 5 758
遇见更好的自我
遇见更好的自我 2020-12-16 16:14

file_get_contents with https hosts works just fine, except for a particular host (test api server from some company - ip whitelisted, can\'t give you URL to test). This rule

相关标签:
5条回答
  • 2020-12-16 16:30

    You could try to debug this with Wireshark -- you might get a better idea of what goes wrong, you should see which SSL error occurs.

    0 讨论(0)
  • 2020-12-16 16:38

    only install this

    yum install ca-certificates.noarch
    
    0 讨论(0)
  • 2020-12-16 16:41

    You missed verify_peer_name. If you set that to false as well, the request works:

    $arrContextOptions=array(
        "http" => array(
            "method" => "POST",
            "header" => 
                "Content-Type: application/xml; charset=utf-8;\r\n".
                "Connection: close\r\n",
            "ignore_errors" => true,
            "timeout" => (float)30.0,
            "content" => $strRequestXML,
        ),
        "ssl"=>array(
            "allow_self_signed"=>true,
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    );
    
    file_get_contents("https://somedomain:2000/abc/", false, stream_context_create($arrContextOptions));
    
    0 讨论(0)
  • 2020-12-16 16:41

    try this code :

    $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);
    }
    

    if you don't get error , i think problem (with file_get_contents) is form client php configuration otherwise from server configuration.

    0 讨论(0)
  • 2020-12-16 16:50

    dont' know if this will actually help, but do try removing the SSL options from your option array.

    The reason behind this: according to http://www.php.net/manual/en/context.ssl.php , verify_peer is false by default.

    allow_self_signed REQUIRES verify_peer, and is false by default.

    From the above, I gather that allow_self_signed probably overrides your setting for verify_peer.

    So please try without any option for SSL, or without the allow_self_signed, and let us know if that helped any.

    0 讨论(0)
提交回复
热议问题