2015-08-26 49 views
0

我使用https://github.com/jamesiarmes/php-ews库来访问我的交换账户。异常处理ExchangeWebServices php-ews

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

$ews = new ExchangeWebServices("outlook.office365.com", "[email protected]", "test123"); 

$request = new EWSType_FindItemType(); 

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

但如果凭据错了,它抛出一个异常作为

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

会导致网站有什么办法获得响应为错误的“失败”或一些布尔值,而不是信息?

回答

1

有没有办法获得响应的布尔,但你可以做这样的事情

$ews = new ExchangeWebServices("outlook.office365.com", "[email protected]", "test123"); 

$request = new EWSType_FindItemType(); 

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

此外,PHP-EWS的那个版本是过时和没有维护的。我可以建议你试试https://github.com/Garethp/php-ews

+0

谢谢parker :)我会用你建议的库。 Btwn与我使用的有很多不同吗? –

+0

有点差别,是的。一般的结构是一样的,但有一些比较容易使用,但如果你想要的话,你可以像现在使用的那样使用它。您仍然可以执行$ ews = new ExchangeWebServices($ server,$ username,$ password); $ ews->的FindItem();虽然。 –