使用 Azure 存储 JS 客户端库上传图像会引发错误:“拒绝设置不安全 header “用户代理””
网络选项卡中的所有请求都是 200 或 201,看起来 xhr 请求正在运行。是否可以在调用后不设置此 header 或将其过滤掉?我想避免控制台中出现此错误。 https://github.com/Azure/azure-storage-node#azure-storage-javascript-client-library-for-browsers
最佳答案
已经测试了您提到的链接中的示例azurestoragejs-2.9.100-preview
,它在我这边没有导致错误(Chrome 和 Firefox)。
打开azure-storage.blob.js
lib文件,搜索变量var unsafeHeaders
并检查user-agent
是否在其列表中。我在我这边看到了,删除后重现了你的问题。因此您的文件中可能缺少它。
如果你的库没有被破坏,你可以忽略这个“错误”,因为没有任何问题,而且都是由存储库和浏览器实现的。
说明:
当http请求执行时,该库中的方法将确保unsafeHeaders
列表中的 header 不会被xhr
设置。如果没有,浏览器将抛出警告,正如您所看到的,因为这是 xhr standard 的要求。 .
请参阅此库中的注释。
This check is not necessary, but it prevents warnings from browsers about setting unsafe headers.To be honest I'm not entirely sure hiding these warnings is a good thing, but http-browserify did it, so I will too.
一切对你来说都有效,可能已经证明检查是不必要
。也在 xhr standard ,user-agent
不再是不安全的 header ,但浏览器无法跟上。
关于javascript - Azure 存储 Javascript 库 "createBlobServiceWithSas"引发错误 : Refused to set unsafe header "user-agent",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50725776/