c# - MTOM - 在 VS 2010 中读取时遇到无效的 MIME 内容类型 header

标签 c# .net parsing c#-4.0 mtom

我在磁盘上有一个 MTOM 响应,我正在尝试加载和解析该响应。 在创建 MTOM 阅读器时,我不断收到错误消息。

Invalid MIME content-type header encountered on read.

这是一个错误还是内容类型的 header 真的意味着 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
            );

最佳答案

你的数据有几个问题:

  • 您需要在 Content-Type header 中对边界字符串进行编码,因为它包含 ? 字符。
  • 第 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--

关于c# - MTOM - 在 VS 2010 中读取时遇到无效的 MIME 内容类型 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10546123/

相关文章:

jquery parseHTML 没有按预期工作

c# - 使用带有登录页面的 HttpWebRequest 发送数据

c# - 当我在 ins asp.net core 3.1 中工作时收到此错误值不能为空。 (参数 'connectionString')

c# - 为什么 MongoDB 中的多个 session 比一个 session 更快?

c# - 将消息从 Azure 服务总线队列发送到新的 asb 队列

c# - 单声道上的 ASP.NET - 找不到方法 PageAsyncTask

c# - 如何使用 newtonsoft json 解析 3 级嵌套数组

c# - 如何正确地将我的 ContextMenu 命令绑定(bind)到 RelayCommand?

javascript - 正则表达式与 JavaScript

python - 我可以让 Beautiful Soup 保持属性排序和行缩进吗