【问题标题】:Connecting to Microsoft Exchange 2007 through EWS with PHP & Curl使用 PHP 和 Curl 通过 EWS 连接到 Microsoft Exchange 2007
【发布时间】:2013-04-08 12:28:28
【问题描述】:

在使用 PHP - Curl - 和 Soapui(构建和验证必要的 soap/xml 脚本以在 Curl Postfields 中发送)时,我发现在尝试将联系人添加到默认联系人时会返回所有内容文件夹是 xml 格式的 wsdl 定义。我相信我已经通过使用设置为的 Curl 代码解决了我之前的一些问题:

$ch = curl_init('https://'.$host.'/ews/services.wsdl'); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8' , 'Expect:')); 
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET" ); *this resolves the 405 http code return*
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlstr);
$response = curl_exec($ch);

$xmlstr中的数据是:

$xmlstr = <<<XML
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <soap:Body>
      <CreateItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
         <SavedItemFolderId xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
            <DistinguishedFolderId Id="contacts" xmlns="http://schemas.microsoft.com/exchange/services/2006/types"/>
         </SavedItemFolderId>
         <Items xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
            <Contact xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
               <FileAs>Friend A</FileAs>
               <GivenName>Don</GivenName>
               <CompanyName>AdventureWorks</CompanyName>
               <EmailAddresses>
                  <Entry Key="EmailAddress1">don@example.com</Entry>
               </EmailAddresses>
            </Contact>
         </Items>
      </CreateItem>
   </soap:Body>
</soap:Envelope>
XML;

来自服务器的响应/返回是:

HTTP/1.1 200 正常
内容类型:文本/xml
最后修改时间:格林威治标准时间 2013 年 2 月 5 日星期二 23:00:32
接受范围:字节
ETag:“0685999f43ce1:0”
服务器:Microsoft-IIS/7.5
持久身份验证:true
X-Powered-By:ASP.NET
日期:2013 年 4 月 8 日星期一 10:13:46 GMT
内容长度:101206

后跟来自 wsdl 文件的 xml 格式定义。

我会很感激这方面的一些指导。我在几种编码语言方面经验丰富,但我目前不了解soap/xml 和PHP 中的Curl 组件。

【问题讨论】:

    标签: php soap curl exchange-server exchangewebservices


    【解决方案1】:

    我现在已经解决了这个问题。本质上我使用的 URL 是不正确的。 Curl_init 应该是

    $ch = curl_init('https://'.$host.'/EWS/Exchange.asmx');
    

    并且setopts应该改为:

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8')); 
    curl_setopt($ch, CURLOPT_POST, true);
    

    你不需要:

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET" );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      • 1970-01-01
      • 2019-09-12
      相关资源
      最近更新 更多