EIPHTTPProtocolExceptionPeer exception using PutBlock with array of bytes all set to zero

♀尐吖头ヾ 提交于 2019-12-11 02:16:16

问题


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).

For example:

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);

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

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.'.

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?

Thanks for any help.


回答1:


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

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



来源:https://stackoverflow.com/questions/9307637/eiphttpprotocolexceptionpeer-exception-using-putblock-with-array-of-bytes-all-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!