duanqiao2006 2012-05-09 12:30
浏览 71
已采纳

EWS呼叫无法检索电子邮件,但仅针对特定电子邮件

Problem Found: Part of the response (Message body) contains "" which is an invalid XML character. Any idea how to remove it?

I'm using Exchange Web Services to pull in a large number of emails from an Inbox. It worked for the first 1141 emails, but it is failing on 1142 (Skipping ahead to 1143 works fine). I have no idea why it's failing to retrieve the email, but the error I'm getting is this:

Uncaught SoapFault exception: [Client] looks like we got no XML document 

I outputted the response XML to a file for 1142 and 1143, and the only difference was the ItemId line (As expected).

The email does exist in the Inbox, although it contains some odd characters (Represented by those weird square symbols).

I am using a slightly modified version of the php-ews library. Here is part of my code:

<?php
$response = $ews->FindItem($Request);
$items = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->Message;

foreach ( $items as $item ) {
    $ItemRequest = new EWSType_FindItemType();

    $ItemRequest->ItemShape = new EWSType_ItemResponseShapeType();
    $ItemRequest->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
    $ItemRequest->ItemShape->BodyType = EWSType_BodyTypeResponseType::TEXT;
    $ItemRequest->ItemShape->BodyTypeSpecified = true;

    $ItemRequest->ItemIds = new EWSType_NonEmptyArrayOfBaseItemIdsType();
    $ItemRequest->ItemIds->ItemId = new EWSType_ItemIdType();
    $ItemRequest->ItemIds->ItemId->Id = $item->ItemId->Id;

    $response = $ews->GetItem( $ItemRequest ); // Code fails here
}

So I have no idea why the request would fail. I've tried adding the option "exceptions" => 0, "trace" => 1, an d I can see that __last_response DOES contain the response I was expected. Why did it mysteriously fail even though I got back the right response?

  • 写回答

1条回答 默认 最新

  • dougou7782 2012-05-09 13:19
    关注

    I fixed the issue by extending my SoapClient class and implementing a __doRequest method that cleaned invalid characters from the XML message.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起