gpt4 book ai didi

ajax - CORS 和 Azure 存储 (PHP)

转载 作者:行者123 更新时间:2023-12-03 03:17:46 33 4
gpt4 key购买 nike

我正在尝试使用适用于 Windows Azure 的 PHP SDK,它不支持 CORS,也不支持共享访问 key 。

在重写 SDK 以允许我生成 SAS 和必需的查询字符串,并为感恩节更新重写它以允许通过 REST API 对存储进行 CORS 更新后,我遇到了困难。

我成功创建了 SAS,并且可以通过它们读入文件。同样,我的 CORS 请求如下:

<StorageServiceProperties>
<Cors>
<CorsRule>
<AllowedOrigins>
*
</AllowedOrigins>
<AllowedMethods>
GET, PUT, POST, DELETE, HEAD, OPTIONS
</AllowedMethods>
<MaxAgeInSeconds>
500
</MaxAgeInSeconds>
<ExposedHeaders>
x-ms-meta-data*,x-ms-meta-customheader
</ExposedHeaders>
<AllowedHeaders>
x-ms-meta-target*,x-ms-meta-customheader
</AllowedHeaders>
</CorsRule>
</Cors>
<DefaultServiceVersion>
2013-08-15
</DefaultServiceVersion>
</StorageServiceProperties>

我收到回复 HTTP_Request2_Response Object ( [version:protected] => 1.1 [code:protected] => 202 [reasonPhrase:protected] => Accepted [effectiveUrl:protected] => <mysite>?restype=service&comp=properties [headers:protected] => Array ( [transfer-encoding] => chunked [server] => Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0 [x-ms-request-id] => 59bc0e05-4767-4953-9df1-2d2a6a9054bc [x-ms-version] => 2013-08-15 [date] => Fri, 13 Dec 2013 11:23:49 GMT ) [cookies:protected] => Array ( ) [lastHeader:protected] => date [body:protected] => [bodyEncoded:protected] => 1 )

我还通过对输入的任何部分进行错误检查,它确实失败并发送 400 个失败响应。

所以现在我在网页上编写了一个应用程序,该应用程序应该允许用户将文件直接上传到存储帐户,但我仍然收到错误

OPTIONS <mystorage> 403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.) jquery.js:8706
OPTIONS <mystorage> No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<mysite>' is therefore not allowed access. jquery.js:8706
XMLHttpRequest cannot load <mystorage>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin <mysite> is therefore not allowed access. azure_blob.html:1
error

我不知道从这里继续哪里...我感觉我已经启用了 CORS,而且我感觉 SAS 正在工作,但它告诉我我的存储帐户的 CORS 支持已关闭,并且我不知道如何通过 REST API/Azure SDK 检查这是否属实

编辑:谢谢 Guarav...问题确实是添加 content-type到我的标题

对于即将看到此内容的任何人:我将修复代码,使其变得更好,并实现一些其他内容,然后向 PHP SDK 提交拉取请求,这样您就不必再次经历此过程。

我仅针对新更新实现了 CORS。在提交请求之前,我将进去实现其他 serviceProperty 更新,也许还有其他事情。

最佳答案

尝试在 <AllowedHeaders> 中添加以下 header CORS 请求中的部分:

  • x-ms-*(将处理 header 类型 x-ms-blob-type 等)
  • Content-Length(我在 CORS 实验中注意到,这是由浏览器自动添加的,如果我不将其包含在 CORS header 中,则会收到 403 错误)。
  • 接受(我在 CORS 实验中注意到,这是由浏览器自动添加的,如果我不将其包含在 CORS header 中,则会收到 403 错误)。
  • 内容类型

或者您可以通过 Fiddler 等工具跟踪请求并查看请求中发送的所有请求 header ,并将它们与您的 CORS 规则进行匹配。

关于ajax - CORS 和 Azure 存储 (PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20565716/

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