How to enable HTTPS stream wrappers

前端 未结 4 1103
夕颜
夕颜 2020-11-27 21:09

I installed php5 on my windows system and tried to execute the following script with a command-line console:



        
4条回答
  •  青春惊慌失措
    2020-11-27 21:52

    The file_get_contents line, at the end of your script, is trying to send an HTTPS request -- see the URL in $req, which starts by 'https://ec2...'.

    For this to be possible, PHP needs a "wrapper" to send HTTPS requests -- which doesn't seem to be installed on your system ; which means you cannot send HTTPS requests using the fopen familly of functions.

    For more informations about stream wrappers, if you are curious, you can take a look at List of Supported Protocols/Wrappers, and, in your case, HTTP and HTTPS.

    You'll either have to install the HTTPs wrapper -- on Windows, I have no idea how to do that, unfortunately...


    Or you'll have to use something else that file_get_contents to send your HTTPS request -- I would use the functions provided by the curl extension (Here, too, not sure it will work "out of the box", though :-( ).

    For an example, you can take a look at what's proposed on the manual page of curl_exec :

    // create a new cURL resource
    $ch = curl_init();
    
    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    // grab URL and pass it to the browser
    curl_exec($ch);
    
    // close cURL resource, and free up system resources
    curl_close($ch);
    

    Note you'll probably have to set a couple more options, using curl_setopt -- you should go through that page : there are a lot of useful options ;-)


    As a sidenote, you are using this line at the beginning of your script :

    $creds = parse_ini_file('/etc/aws.conf');
    

    The path /etc/aws.conf feels strange, as you said you are using a Windows system : this looks like the kind of path one would use on an UNIX/Linux system.

提交回复
热议问题