0

我使用https://github.com/jamesiarmes/php-ews库来访问我的交换帐户。

如果我使用正确的凭据来创建 ExchangeWebServices 对象,我会得到准确的响应。

$ews = new ExchangeWebServices("outlook.office365.com", "tes@abc.com", "test123");

$request = new EWSType_FindItemType();

$response = $ews->FindItem($request);

但是如果凭据错误,它会通过抛出异常来破坏站点

EWS_Exception: SOAP client returned status of 401 in ExchangeWebServices->processResponse() 

有什么方法可以将响应作为“失败”或某个布尔值而不是错误消息?

4

1 回答 1

2

没有办法将响应作为布尔值,但你可以做类似的事情

$ews = new ExchangeWebServices("outlook.office365.com", "tes@abc.com", "test123");

$request = new EWSType_FindItemType();

try {
    $response = $ews->FindItem($request);
} catch (\Exception $e) {
    //The response failed.
}

此外,该版本的 php-ews 已过时且未维护。我可以建议你试试https://github.com/Garethp/php-ews

于 2015-08-27T07:53:48.100 回答