我在磁盘上有一个MTOM响应,我正在尝试加载和解析响应。
创建MTOM阅读器时,我不断收到错误消息。
Invalid MIME content-type header encountered on read.
这是错误还是内容类型的标头确实意味着Visual Studio无法理解内容类型?
MIME-Version: 1.0
Content-Type: Multipart/Related;boundary=DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM;
type="application/xop+xml";
start="<[email protected]>";
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/xop+xml; charset=utf-8; type="application/xop+xml"
content-id: <[email protected]>
<ItemOperations xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:B="HMMAIL:" xmlns:D="HMSYNC:" xmlns="ItemOperations:"><Status>1</Status><Responses><Fetch><ServerId>E631966A-9439-11E1-8E7B-00215AD9A7B8</ServerId><Status>1</Status><Message><xop:Include href="cid:[email protected]" /></Message></Fetch></Responses></ItemOperations>
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/octet-stream
content-id: <[email protected]>
这是创建MTOM阅读器的简单代码。
XmlDictionaryReader mtomReader = XmlDictionaryReader.CreateMtomReader
(
fStream,
Encoding.UTF8,
XmlDictionaryReaderQuotas.Max
);
最佳答案
您的数据中存在几个问题:
您需要在Content-Type标头中对边界字符串进行编码,因为它包含?
字符。
第5行到最后一行是缩进的-您需要删除前导空格
您缺少结尾边界字符串
这是对我有用的修改后的内容:
MIME-Version: 1.0
Content-Type: Multipart/Related;boundary="DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM"";
type="application/xop+xml"";
start="<[email protected]>"";
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/xop+xml; charset=utf-8; type="application/xop+xml""
content-id: <[email protected]>
<ItemOperations xmlns:xop="http://www.w3.org/2004/08/xop/include"" xmlns:B=""HMMAIL:"" xmlns:D=""HMSYNC:"" xmlns=""ItemOperations:""><Status>1</Status><Responses><Fetch><ServerId>E631966A-9439-11E1-8E7B-00215AD9A7B8</ServerId><Status>1</Status><Message><xop:Include href=""cid:[email protected]"" /></Message></Fetch></Responses></ItemOperations>
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/octet-stream
content-id: <[email protected]>
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM--