在使用PHP - Curl - 和Soapui(构建和验证必要的soap / xml脚本以在Curl Postfields中发送)时,我发现在尝试将所有联系人添加到默认联系人时,我都会返回folder是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 OK
内容类型:text / xml
Last-Modified:Tue,05 Feb 2013 23:00:32 GMT
Accept-Ranges:bytes
ETag:“0685999f43ce1:0”
服务器:Microsoft-IIS / 7.5
Persistent-Auth:真实的
X-Powered-By:ASP.NET
日期:星期一,2013年4月8日10:13:46 GMT
内容长度:101206
后跟wsdl文件中的xml格式化定义。
我会感谢你的一些指示。我在几种编码语言方面经验丰富,但PHP中的soap / xml和Curl组件不在我目前的知识范围内。
答案 0 :(得分: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" );