我没有可能将我的请求编码到base64,并根据我不应该的文档,但我无法弄清楚.
如果我Base64编码它工作正常:
<QueueMessage>
<MessageText>PHNhbXBsZT5zYW1wbGUgbWVzc2FnZTwvc2FtcGxlPg==</MessageText>
</QueueMessage>
这会将解码后的消息添加到队列中:
<sample>sample message</sample>
根据文件(https://msdn.microsoft.com/sv-se/library/azure/dd179346.aspx)
A message must be in a format that can be included in an XML request
with UTF-8 encoding. To include markup in the message, the contents of
the message must either be XML-escaped or Base64-encode. Any XML
markup in the message that is not escaped or encoded will be removed
before the message is added to the queue.
试图添加(而不是PHNhbXBsZT5zYW1wbGUgbWVzc2FnZTwvc2FtcGxlPg ==):
<sample>sample message</sample>
成功,但在尝试查看队列中的消息时,它只响应:
The input is not a valid Base-64 string as it contains a non-base 64
character, more than two padding characters, or an illegal character
among the padding characters.
有人知道如何将正确的原始xml转义请求消息发送到存储队列吗?
完整请求(没有密钥和名称):
POST https://xxxxxxx.queue.core.windows.net/testqueue/messages?sv=2015-04-05&ss=q&srt=sco&sp=a&se=2026-11-11T20:24:03Z&st=2016-11-11T12:24:03Z&spr=https&sig=xxxxxxxxxxxxxxxxx%3D HTTP/1.1
User-Agent: Fiddler
Host: XXXXX.queue.core.windows.net
Content-Type: text/plain
Content-Length: 64
<QueueMessage>
<MessageText><sample>sample message</sample></MessageText>
</QueueMessage>
最佳答案 我在调用AsString属性时遇到格式错误,因为默认情况下,从存储队列返回的消息是base64编码的.
CloudQueue对象具有设置为true的EncodeMessage属性.切换到假,一切正常.这是我的代码:
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference(ClientQueueName);
queue.EncodeMessage = false;
CloudQueueMessage retrievedMessage = queue.GetMessage();
ClientQueueName是一个字符串,在Azure上保存我的队列名称.我想在发送之前需要将属性设置为false.