如何启用HTTPS流包装器

Tam*_*pox 17 php amazon

我在我的Windows系统上安装了php5,并尝试使用命令行控制台执行以下脚本:

<?php
// load in credentials
$creds = parse_ini_file('/etc/aws.conf');

// Define query string keys/values
$params = array(
    'Action' => 'DescribeAvailabilityZones',
    'AWSAccessKeyId' => $creds['access_key'],
    'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
    'Version' => '2008-05-05',
    'ZoneName.0' => 'us-east-1a',
    'ZoneName.1' => 'us-east-1b',
    'ZoneName.2' => 'us-east-1c',
    'SignatureVersion' => 2,
    'SignatureMethod' => 'HmacSHA256'
);

// See docs
// http://tr.im/jbjd
uksort($params, 'strnatcmp');
$qstr = '';
foreach ($params as $key => $val) {
    $qstr .= "&{$key}=".rawurlencode($val);
}
$qstr = substr($qstr, 1);

// Signature Version 2
$str = "GET\n"
     . "ec2.amazonaws.com\n"
     . "/\n"
     . $qstr;

// Generate base64-encoded RFC 2104-compliant HMAC-SHA256
// signature with Secret Key using PHP 5's native 
// hash_hmac function.
$params['Signature'] = base64_encode(
    hash_hmac('sha256', $str, $creds['secret_key'], true)
);

// simple GET request to EC2 Query API with regular URL 
// encoded query string
$req = 'https://ec2.amazonaws.com/?' . http_build_query(
    $params
);
$result = file_get_contents($req);

// do something with the XML response
echo $result;
Run Code Online (Sandbox Code Playgroud)

但是它说它无法找到包装器"https"并询问我在配置PHP时是否忘记启用它.

有什么问题,如何解决?

Dre*_*rew 41

1:检查安装了哪些包装.

<?php var_dump(stream_get_wrappers()); ?>
Run Code Online (Sandbox Code Playgroud)

2:如果您没有在列表中看到"https",请从php.ini添加到/ uncomment

extension=php_openssl.dll
Run Code Online (Sandbox Code Playgroud)

重新启动服务器*,完成.

*如果服务器无法重启,请从某个地方下载php_openssl.dll并将其粘贴在php.ini文件中定义的扩展目录中,重新启动服务器,说一些地狱玛丽并祈祷.

  • 通过命令行:`php -r var_dump(stream_get_wrappers());` (2认同)

Pas*_*TIN 10

file_get_contents脚本末尾的行正在尝试发送HTTPS请求 - 请参阅以中$req开头的URL 'https://ec2...'.

为了实现这一点,PHP需要一个"包装器"来发送HTTPS请求 - 这似乎没有安装在您的系统上; 这意味着您无法使用家庭fopen功能发送HTTPS请求.

有关流包装器的更多信息,如果您感到好奇,可以查看支持的协议/包装列表,以及在您的情况下,HTTP和HTTPS.

你要么必须安装HTTPs包装器 - 在Windows上,我不知道怎么做,不幸的是......


或者你将不得不使用其他东西file_get_contents来发送你的HTTPS请求 - 我会使用curl扩展提供的功能(这里也不确定它是否可以"开箱即用",但是:-().

例如,您可以查看手册页上提出的内容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);
Run Code Online (Sandbox Code Playgroud)

请注意,您可能需要设置更多选项,使用curl_setopt- 您应该浏览该页面:有很多有用的选项;-)


作为旁注,您在脚本的开头使用此行:

$creds = parse_ini_file('/etc/aws.conf');
Run Code Online (Sandbox Code Playgroud)

路径/etc/aws.conf感觉很奇怪,正如你所说的使用Windows系统:这看起来像是在UNIX/Linux系统上使用的那种路径.