file_get_contents(): SSL operation failed with code 1, Failed to enable crypto

前端 未结 16 1756
情歌与酒
情歌与酒 2020-11-22 04:31

I’ve been trying to access this particular REST service from a PHP page I’ve created on our server. I narrowed the problem down to these two lines. So my PHP page looks li

16条回答
  •  粉色の甜心
    2020-11-22 04:57

    You shouldn't just turn off verification. Rather you should download a certificate bundle, perhaps the curl bundle will do?

    Then you just need to put it on your web server, giving the user that runs php permission to read the file. Then this code should work for you:

    $arrContextOptions=array(
        "ssl"=>array(
            "cafile" => "/path/to/bundle/cacert.pem",
            "verify_peer"=> true,
            "verify_peer_name"=> true,
        ),
    );
    
    $response = file_get_contents("https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json", false, stream_context_create($arrContextOptions));
    

    Hopefully, the root certificate of the site you are trying to access is in the curl bundle. If it isn't, this still won't work until you get the root certificate of the site and put it into your certificate file.

提交回复
热议问题