我按照教程使用REST调用BLOB的内容,也遇到的是401错误,这是什么情况?还有人也遇到了吗?
1条回答 默认 最新
- WillShao_MSFT 2015-03-27 07:04关注
您好,
请问您使用的是REST中的哪一个方法?据我所知,如果使用REST去调用blob中内容是,复杂的地方主要是在构造签名,首先我建议您先阅读下这篇文档:
https://msdn.microsoft.com/zh-cn/library/azure/dd179428.aspx
例如该方法:public void PutBlob(String containerName, String blobName) { String requestMethod = "PUT"; String urlPath = String.Format("{0}/{1}", containerName, blobName); String storageServiceVersion = "2012-02-12"; String dateInRfc1123Format = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture); String content = "Andrew Carnegie was born in Dunfermline"; UTF8Encoding utf8Encoding = new UTF8Encoding(); Byte[] blobContent = utf8Encoding.GetBytes(content); Int32 blobLength = blobContent.Length; const String blobType = "BlockBlob"; String canonicalizedHeaders = String.Format( "x-ms-blob-type:{0}\nx-ms-date:{1}\nx-ms-version:{2}", blobType, dateInRfc1123Format, storageServiceVersion); String canonicalizedResource = String.Format("/{0}/{1}", AzureStorageConstants.Account, urlPath); String stringToSign = String.Format( "{0}\n\n\n{1}\n\n\n\n\n\n\n\n\n{2}\n{3}", requestMethod, blobLength, canonicalizedHeaders, canonicalizedResource); String authorizationHeader = Utility.CreateAuthorizationHeader(stringToSign); Uri uri = new Uri(AzureStorageConstants.BlobEndPoint + urlPath); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = requestMethod; request.Headers.Add("x-ms-blob-typeobType); request.Headers.Add("x-ms-dateteInRfc1123Format); request.Headers.Add("x-ms-versionorageServiceVersion); request.Headers.Add("AuthorizationthorizationHeader); request.ContentLength = blobLength; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(blobContent, 0, blobLength); } using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { String ETag = response.Headers["ETag"]; } }
我们需要构造出shared key,同时注意header中的各个信息。
处理rest问题和调试rest错误时,我个人建议您可以使用fiddler去troubleshoot您的reqest请求,去解决问题。
同时,建议您参考这个博客:https://convective.wordpress.com/2010/08/18/examples-of-the-windows-azure-storage-services-rest-api/
Regards,
Will
如果您想进一步了解Windows Azure, Windows Azure 官网欢迎您的访问本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 求差集那个函数有问题,有无佬可以解决
- ¥15 【提问】基于Invest的水源涵养
- ¥20 微信网友居然可以通过vx号找到我绑的手机号
- ¥15 寻一个支付宝扫码远程授权登录的软件助手app
- ¥15 解riccati方程组
- ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
- ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
- ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
- ¥50 树莓派安卓APK系统签名
- ¥65 汇编语言除法溢出问题