rest - Cannot retrieve file list from Azure File Storage using REST API and curl
问题描述
I'm trying to retrieve the list of files stored in an Azure File Storage account using the REST API and curl, I correctly computed headers according to the documentation by using the shared key , but curl request neither returns the files list nor any error message.
Here is my request and the response:
curl -v -H "Authorization: SharedKey myaccount:bAJKeY0xyOZLSJOLDoHfXXOqfA4kOGo1DVFP3BejhY8=" -H "x-ms-date:Mon, 13 Aug 2018 15:22:31 GMT" -H "x-ms-version:2017-07-29" --url https://myaccount.file.core.windows.net/myshare/mydir?restype=directory&comp=list
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 52.239.140.8...
* Connected to myaccount.file.core.windows.net (52.239.140.8) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 597 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_256_GCM_SHA384
* server certificate verification OK
* server certificate status verification SKIPPED
* common name: *.file.core.windows.net (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3
* subject: CN=*.file.core.windows.net
* start date: Thu, 09 Nov 2017 05:42:03 GMT
* expire date: Sat, 09 Nov 2019 05:42:03 GMT
* issuer: C=US,ST=Washington,L=Redmond,O=Microsoft Corporation,OU=Microsoft IT,CN=Microsoft IT TLS CA 5
* compression: NULL
* ALPN, server did not agree to a protocol
GET /myshare/mydir?restype=directory HTTP/1.1
Host: myaccount.file.core.windows.net
User-Agent: curl/7.47.0
Accept: */*
Authorization: SharedKey
myaccount:bAJKeY0xyOZLSJOLDoHfXXOqfA4kOGo1DVFP3BejhY8=
x-ms-date:Mon, 13 Aug 2018 15:22:31 GMT
x-ms-version:2017-07-29
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Last-Modified: Fri, 27 Apr 2018 16:11:14 GMT
ETag: "0x8D5AC597FF96B3D"
Server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 75d6d7c8-f01a-0011-5b19-33104d000000
x-ms-version: 2017-07-29
x-ms-server-encrypted: true
Date: Mon, 13 Aug 2018 15:22:29 GMT
{ [5 bytes data]
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
* Connection #0 to host myaccount.file.core.windows.net left intact
No XML with file list is returned. I tried to retrieve the share list under myaccount and it works, as well as downloading a single file, but I cannot receive the list of files under a directory.
解决方案
两点:
在 curl 命令中查看 url
--url https://myaccount.file.core.windows.net/myshare/mydir?restype=directory&comp=list
您忘记输入网址,
""
因此参数&comp=list
被剪切,因为&
是保留符号。输出也证明了这一点GET /myshare/mydir?restype=directory HTTP/1.1
。通常情况下,如果 url缺少
comp
参数,我们应该得到错误消息 AuthenticationFailed 因为comp
用于生成 SharedKey。但是,您HTTP/1.1 200 OK
使用 SharedKey。根据您获得的响应标头,我猜您
comp
在构造 SharedKey 时也错过了,因此 SharedKey 和 url 能够正确获取目录属性。
推荐阅读
- python - Mongodb 似乎加载了两次数据。不知道为什么,也不确定我是否正确加载了 mongodb
- python - 访问 JSON 文件 python if 语句
- javascript - 检测数据何时插入/更新到 sql
- javascript - 如何使用 rxjs 映射通过另一个不同类型的对象列表过滤出一个可观察的对象列表
- progressive-web-apps - 带有 Onesignal、Nuxtjs 和 Prismic CMS 的动态推送通知
- javascript - 如何使用javascript使```var num = 12;```等于3?
- c# - 尝试从 Visual Studio 获取图像文件时出现异常
- azure-ad-b2c - Azure B2C:使用外部 IDP 进行 REST 调用
- javascript - 在 Qualtrics 中创建固定表
- node.js - 如何将我的团队 Discord 机器人的状态设置为“请勿打扰”并将自定义状态设置为“照顾 Speedo 团队”?