2013-04-08 131 views
1

在使用PHP-Curl和Soapui(构建并验证在Curl Postfields中发送必需的soap/xml脚本)时,我发现我尝试例如,向默认联系人文件夹添加联系人是xml格式的wsdl定义。我相信我已经通过卷曲代码设置为解决我的一些早期的问题:在通过PHP和Curl通过EWS连接到Microsoft Exchange 2007

$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">[email protected]</Entry> 
       </EmailAddresses> 
      </Contact> 
     </Items> 
     </CreateItem> 
    </soap:Body> 
</soap:Envelope> 
XML; 

响应/回报是:HTTP/1.1 200 OK
的Content-Type


文本/ XML的Last-Modified:涂即,2013年2月5日23时〇〇分32秒GMT
接受-范围:字节
的ETag: “0685999f43ce1:0”
服务器:Microsoft-IIS/7.5
持久验证:真
X供电,通过:ASP.NET
日期:星期一,2013年4月8日10时十三分46秒GMT
的Content-Length:101206

,然后从WSDL文件中的XML格式的定义。

我会感激这方面的一些方向。我在几种编码语言方面经验丰富,但soap/xml和PHP中的Curl组件并不在我目前的知识范围内。

回答

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");