简体   繁体   English

MTOM - 在VS 2010中读取时遇到无效的MIME内容类型标头

[英]MTOM - Invalid MIME content-type header encountered on read in VS 2010

I have a MTOM response on the disk and I am trying to load and parse the response. 我在磁盘上有一个MTOM响应,我正在尝试加载和解析响应。 While creating an MTOM reader I keep getting the error. 在创建MTOM阅读器时,我不断收到错误。

Invalid MIME content-type header encountered on read.

Is this a bug or does the header for content-type really means that Visual Studio cannot understand the content type? 这是一个错误还是内容类型的标题真的意味着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>

Here is the simple code to create the MTOM reader. 以下是创建MTOM阅读器的简单代码。

XmlDictionaryReader mtomReader = XmlDictionaryReader.CreateMtomReader
            (
             fStream,
             Encoding.UTF8,
             XmlDictionaryReaderQuotas.Max
            );

There are several problems in your data: 您的数据存在以下问题:

  • You need to encode boundary string in your Content-Type header because it contains ? 您需要在Content-Type标头中编码边界字符串,因为它包含? character. 字符。
  • Lines 5 to end are indented - you need to remove the leading spaces 第5行到结尾是缩进的 - 您需要删除前导空格
  • You are missing the ending boundary string 您缺少结束边界字符串

Here is the modified content that worked for me: 以下是修改后的内容对我有用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM