我在磁盘上有一个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="<DeltaSyncMTOMFetchResponse@mail.services.live.com>";
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/xop+xml; charset=utf-8; type="application/xop+xml"
content-id: <DeltaSyncMTOMFetchResponse@mail.services.live.com>
<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:1.634715231374437235@example.org" /></Message></Fetch></Responses></ItemOperations>
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/octet-stream
content-id: <1.634715231374437235@example.org>
下面是创建 MTOM 读取器的简单代码。
XmlDictionaryReader mtomReader = XmlDictionaryReader.CreateMtomReader
(
fStream,
Encoding.UTF8,
XmlDictionaryReaderQuotas.Max
);
数据中存在几个问题:
- 需要在内容类型标头中对边界字符串进行编码,因为它包含
?
字符。
第 - 5 行到结尾是缩进的 - 您需要删除前导空格
- 缺少结束边界字符串
以下是对我有用的修改内容:
MIME-Version: 1.0
Content-Type: Multipart/Related;boundary="DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM"";
type="application/xop+xml"";
start="<DeltaSyncMTOMFetchResponse@mail.services.live.com>"";
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/xop+xml; charset=utf-8; type="application/xop+xml""
content-id: <DeltaSyncMTOMFetchResponse@mail.services.live.com>
<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:1.634715231374437235@example.org"" /></Message></Fetch></Responses></ItemOperations>
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM
content-transfer-encoding: binary
content-type: application/octet-stream
content-id: <1.634715231374437235@example.org>
--DeltaSync91ABCB4AF5D24B8F988B77ED7A19733D?MTOM--