使用PutBlock的EIPHTTPProtocolExceptionPeer异常,其字节数组都设置为零 [英] EIPHTTPProtocolExceptionPeer exception using PutBlock with array of bytes all set to zero

查看:104
本文介绍了使用PutBlock的EIPHTTPProtocolExceptionPeer异常,其字节数组都设置为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Delphi XE2 Update 3我在将零字节的块上载到Azure时遇到问题.当我说零字节时,我的意思是一个字节数组,每个元素都设置为零(长度不为零).

Using Delphi XE2 Update 3 I'm having a problem uploading a block of zero bytes to Azure. When I say zero bytes, I mean an array of bytes with each element set to zero (it's not zero length).

例如:

var
  ConInfo: TAzureConnectionInfo;
  RespInfo: TCloudResponseInfo;
  BlobService: TAzureBlobService;
  Content: TBytes;
  MD5: String;
  Hasher: TIdHashMessageDigest5;
begin
  ConInfo:=TAzureConnectionInfo.Create(self);
  ConInfo.AccountName:='YOUR ACCOUNT NAME';
  ConInfo.AccountKey:='YOUR ACCOUNT KEY';
  ConInfo.Protocol:='http';

  BlobService:=TAzureBlobService.Create(ConInfo);    
  RespInfo:=TCloudResponseInfo.Create;

  SetLength(Content, 1048576); // 1 MByte
  FillMemory(@Content[0], 1048576, 0); // << --- fill it with anything except 0 and it works

  Hasher:=TIdHashMessageDigest5.Create;
  MD5:=Data.Cloud.CloudAPI.EncodeBytes64(Hasher.HashBytes(Content));
  Hasher.Free;

  BlobService.PutBlock('CONTAINER NAME', 'BLOB NAME', MD5, Content, MD5, '', RespInfo);

如果运行了以上代码,则对PutBlock的调用将引发异常:

If the above code is run then an exception is raised on the call to PutBlock:

Project Project1.exe引发异常类 消息为"HTTP/1.1 403 EIPHTTPProtocolExceptionPeer的服务器失败 验证请求.确保授权值 标头的格式正确,包括签名.'.

Project Project1.exe raised exception class EIPHTTPProtocolExceptionPeer with message 'HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.'.

但是,如果您更改 FillMemory 行,以使其充满1(或除零以外的任何值),那么它将正常工作而不会出现错误.为什么?

But if you change the FillMemory line so that it fills it with 1's (or anything but zero), then it works without error. Why?

感谢您的帮助.

推荐答案

令人难以置信的是,问题似乎出在 ttgbNgpWctgMJ0MPORU + LA ==

Unbelievably, it seems that the problem is the block ID value of ttgbNgpWctgMJ0MPORU+LA==

如果将其用作阻止ID,则会收到该错误.

If you use it as a block ID then you get that error.

这篇关于使用PutBlock的EIPHTTPProtocolExceptionPeer异常,其字节数组都设置为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆