gpt4 book ai didi

azure - 向 Azure 容器授予公共(public)权限

转载 作者:行者123 更新时间:2023-12-03 04:19:28 25 4
gpt4 key购买 nike

我正在使用 REST API 在 Azure 存储中创建容器。我想授予公共(public)权限或容器权限,以将 blob 动态上传到容器中。我在 header 中写入“x-ms-blob-public-access:container”,但是当我包含以下错误时

错误

Result HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. Content-Length: 709 Content-Type: application/xml Server: Microsoft-HTTPAPI/2.0 x-ms-request-id: 832b00af-501e-0032-7c96-f1ba27000000 Date: Tue, 22 May 2018 06:29:51 GMT AuthenticationFailedServer failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:832b00af-501e-0032-7c96-f1ba27000000 Time:2018-05-22T06:29:51.7678173ZThe MAC signature found in the HTTP request 'bmJk1ntjZX17woKGTm1YjEaIU3N/NSOXt/a8Gq4lCI0=' is not the same as any computed signature. Server used following string to sign: 'PUT 0 x-ms-blob-public-access:container x-ms-date:Tue, 22 May 2018 06:29:51 GMT x-ms-version:2009-09-19 /dsmsstor1/66-62-108-images restype:container'.Error

我想我也必须将“x-ms-blob-public-access:container”放入 sig 字符串中,但我无法正确执行此操作。帮助我形成正确的签名字符串。即 (PUT\n\n\n0\n\n\n\n\n\n\n\n\nx-ms-date:". $date . "\nx-ms-version:".$version. “\n/dsmsstor1/66-62-108-images\nrestype:容器) 我的代码 ----------

<?php
date_default_timezone_set ( 'GMT' );
$date = date ( "D, j M Y H:i:s T" );
$version = "2009-09-19";
$account_key = 'xxxxxxxxx';

$utf8_encode_str = utf8_encode ("PUT\n\n\n0\n\n\n\n\n\n\n\n\nx-ms-date:". $date . "\nx-ms-version:".$version."\n/dsmsstor1/66-62-108-images\nrestype:container" );
$signature_str = base64_encode(hash_hmac('sha256',$utf8_encode_str, base64_decode($account_key), true));
$header = array (
"x-ms-date: " . $date,
"x-ms-version: " . $version,
"Authorization: SharedKey dsmsstor1:" . $signature_str,
"Content-Length: 0",
"x-ms-blob-public-access:container"
);
$url="https://dsmsstor1.blob.core.windows.net/66-62-108-images?restype=container";
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'PUT' );
curl_setopt ($ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt ($ch, CURLOPT_HEADER, True );
$result = curl_exec ( $ch );
echo ('Result<br/>');
print_r($result);

echo ('Error<br/>');
print_r(curl_error($ch));

curl_close($ch);
?>

最佳答案

您的 $utf8_encode_str 中缺少 x-ms-blob-public-access:container

请尝试更改以下代码行:

$utf8_encode_str = utf8_encode ("PUT\n\n\n0\n\n\n\n\n\n\n\n\nx-ms-date:". $date . "\nx-ms-version:".$version."\n/dsmsstor1/66-62-108-images\nrestype:container" );

$utf8_encode_str = utf8_encode ("PUT\n\n\n0\n\n\n\n\n\n\n\n\nx-ms-blob-public-access:container\nx-ms-date:". $date . "\nx-ms-version:".$version."\n/dsmsstor1/66-62-108-images\nrestype:container" );

关于azure - 向 Azure 容器授予公共(public)权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50461288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com