无法将响应 body 解析为 XML:无法将字符串解析为 XML(视图:

Unable to parse response body into XML: String could not be parsed as XML (View:

我的任务是连接到 s3 存储桶并使用以下文档:

<?php
define('AWS_KEY', 'key in here');
define('AWS_SECRET_KEY', 'key in here');
define('HOST', 'https://console.aws.amazon.com/s3/home?region=us-east-1#');




 use Aws\S3\S3Client;

// Establish connection with DreamObjects with an S3 client.
$client = S3Client::factory(array(
'base_url' => HOST,
'key'      => AWS_KEY,
'secret'   => AWS_SECRET_KEY
 ));

// list owned buckets


$blist = $client->listBuckets();
echo "   Buckets belonging to " . $blist['Owner']['ID'] . ":\n";
foreach ($blist['Buckets'] as $b) {
echo "{$b['Name']}\t{$b['CreationDate']}\n";
}

 // list Bucket contents


 $o_iter = $client->getIterator('ListObjects', array(
'Bucket' => $bucketname
 ));
 foreach ($o_iter as $o) {
  echo "{$o['Key']}\t{$o['Size']}\t{$o['LastModified']}\n";
 }

但是我在标题中得到了错误任何想法我有我的访问密钥但我对如何解决这个问题感到困惑?

硬编码或使用环境变量来传递您的密钥和访问密钥可能不是一个好主意。

更好的设计模式是利用 EC2 角色或使用 SDK 配置文件(有关详细信息,请参阅 http://docs.aws.amazon.com/aws-sdk-php/guide/latest/credentials.html

您使用的 base_url 参数无效,它是控制台的 URL,而不是来自服务的参数。您可以忽略此参数(根据 http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html#client-configuration-options),SDK 会自动为您构建它