【问题标题】:Exception handling ExchangeWebServices php-ews异常处理 ExchangeWebServices php-ews
【发布时间】:2015-08-27 15:53:48
【问题描述】:

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

如果我使用正确的凭据创建 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() 

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

【问题讨论】:

    标签: php-ews


    【解决方案1】:

    无法将响应作为布尔值获取,但您可以执行类似的操作

    $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

    【讨论】:

    • 谢谢帕克 :) 我会使用你建议的库。 Btwn 我使用的和这个有很多不同吗?
    • 有点不同,是的。一般结构是相同的,但有些位更易于使用,但如果您愿意,您可以以与您目前使用的方式相同的方式使用它。您仍然可以执行 $ews = new ExchangeWebServices($server, $username, $password); $ews->FindItem();不过。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 2016-02-29
    • 2016-03-07
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多