PHP-EWS"Soap客户端返回的状态为404" [英] PHP-EWS "Soap client returned status of 404"

查看:285
本文介绍了PHP-EWS"Soap客户端返回的状态为404"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用 php-ews 库连接到我的Microsoft Office 365 Exchange电子邮件帐户阅读电子邮件.我已成功连接到它,并且设法检索了所需的电子邮件列表.

So, I'm using php-ews library to connect to my Microsoft Office 365 Exchange Email account to read emails. I've connected successfully to it and I have managed to retrieve a list of emails that I need.

现在的问题是我无法获取消息正文.阅读有关Exchange Web Services的文档时,它说不能使用FindItem()只能使用GetItem()来获取主体,这没关系.

Now the problem is that I cannot get message body. Reading documentation about Exchange Web Services it says that body cannot be fetched with FindItem(), only with GetItem(), and that's okay.

现在我看到的问题如下: 我尝试了所有可能找到的示例,并且代码没有任何错误,只是说"Soap Client返回的状态为404".

Now the problem I'm seeing is following: I tried all possible examples I could find about this, and the code doesn't have any errors, it just says "Soap client returned status of 404".

如果有人知道在哪里寻找解决方案,请告诉我.

If anyone has any idea where to look for the solution, please tell me.

$ews = new Client('outlook.office365.com/EWS/OData/Me/Inbox/Messages', '###', '###', ClientEWS::VERSION_2010_SP2);

    $request = new FindItemType();

    $request->ItemShape = new ItemResponseShapeType();
    $request->ItemShape->BaseShape = DefaultShapeNamesType::DEFAULT_PROPERTIES;
    $request->ItemShape->BodyType = BodyTypeResponseType::BEST;

    $request->Traversal = ItemQueryTraversalType::SHALLOW;

    $request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
    $request->ParentFolderIds->DistinguishedFolderId = new DistinguishedFolderIdType();
    $request->ParentFolderIds->DistinguishedFolderId->Id = DistinguishedFolderIdNameType::INBOX;

    // sort order
    $request->SortOrder = new NonEmptyArrayOfFieldOrdersType();
    $request->SortOrder->FieldOrder = array();
    $order = new FieldOrderType();
    // sorts mails so that oldest appear first
    // more field uri definitions can be found from types.xsd (look for UnindexedFieldURIType)
    $order->FieldURI = new PathToUnindexedFieldType();
    $order->FieldURI->FieldURI = 'item:DateTimeReceived';
    $order->Order = 'Ascending';
    $request->SortOrder->FieldOrder[] = $order;

    try{
        //getting list of all emails - works perfectly
        $result = $ews->FindItem($request);

        if ($result->ResponseMessages->FindItemResponseMessage->ResponseCode == 'NoError' && $result->ResponseMessages->FindItemResponseMessage->ResponseClass == 'Success') {
            $count = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView;
            $request = new GetItemType();
            $request->ItemShape = new ItemResponseShapeType();
            $request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
            for ($i = 0; $i < $count; $i++){
                $message_id = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->Message[$i]->ItemId->Id;

                $messageItem = new ItemIdType();
                $messageItem->Id = $message_id;
                $request->ItemIds->ItemId[] = $messageItem;
            }

            // Here is your response
            // It throws an error here with the message "Soap client returned status of 404"
            $response = $ews->GetItem($request);

            print_r($response);
        }
        //print_r($result);
    } catch(\Exception $e) {
        echo $e->getMessage();
    }

推荐答案

您似乎在尝试为Office365使用新的REST终结点

It looks like your trying to use the new REST endpoint for Office365

'outlook.office365.com/EWS/OData/Me/Inbox/Messages'

但是您尝试发出EWS SOAP请求时,应该用于EWS SOAP的端点是

But your trying to make and EWS SOAP Request, the endpoint you should be using for EWS SOAP is

https://outlook.office365.com/EWS/Exchange.asmx

您可能要考虑使用新的REST接口作为EWS/SOAP的替代方案,但随后需要根据

You might want to consider using the new REST interface as an alternative to EWS/SOAP but you then need to use a REST library.ouauth etc as per https://dev.outlook.com/restapi.

这篇关于PHP-EWS"Soap客户端返回的状态为404"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆