ozntz
toooooooooooooooooooooooooooooooooo
Script to query items from M$ Exchange using Exchange Web Services. My problem is it doesn't find eof on
while (!feof($fp)) { $data .= fgets($fp); }
. Exchange is returning data but the script runs till max time. If I sub (strpos($data,"soap:Envelope") == 0) it returns till the first occurrence but </soap:Envelope is not valid. How can I create a valid EOF?
$realm = "outlook.domain.com";
$hash = "hash";
$fp = fsockopen("tcp://" . $realm, 80, $errno, $errstr, 30);
if (!$fp){echo "$errstr ($errno)";}
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/messages">
<SOAP-ENV:Body>
<FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
Traversal="Shallow">
<ItemShape>
<t:BaseShape>Default</t:BaseShape>
</ItemShape>
<ParentFolderIds>
<t:DistinguishedFolderId Id="inbox"/>
</ParentFolderIds>
</FindItem>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
$httpsend = "POST http://outlook.domain.com/EWS/Exchange.asmx HTTP/1.1\r\n";
$httpsend .= "Host: " . $realm . "\r\n";
$httpsend .= "Connection: Keep-Alive\r\n";
$httpsend .= "Accept: */*\r\n";
$httpsend .= "User-Agent: PHP-SOAP-CURL\r\n";
$httpsend .= "Content-Length: " . strlen($xml) . "\r\n";
$httpsend .= "Content-Type: text/xml; charset=utf-8\r\n";
$httpsend .= "Authorization: BASIC " . $hash . "\r\n\r\n";
$httpsend .= $xml;
fwrite($fp, $httpsend);
$data = "";
while (!feof($fp)) { $data .= fgets($fp); }
fclose($fp);
echo $data;
Expected data return
HTTP/1.1 200 OK
Date: Mon, 29 Jun 2009 19:11:57 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 1342
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><t:ServerVersionInfo MajorVersion="8" MinorVersion="1" MajorBuildNumber="240" MinorBuildNumber="5" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" /></soap:Header><soap:Body><m:FindItemResponse xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"><m:ResponseMessages><m:FindItemResponseMessage ResponseClass="Success"><m:ResponseCode>NoError</m:ResponseCode><m:RootFolder TotalItemsInView="2" IncludesLastItemInRange="true"><t:Items><t:Message><t:ItemId Id="AAAYAERUZXN0QGJpbGxpbmdzY2xpbmljLm9yZwBGAAAAAAAi8z5HQIgMRbIDKl6r1kyVBwDIQB5ZucBgRbu5MlIMCmzKAA8/RX7yAADIQB5ZucBgRbu5MlIMCmzKAA9FrwiQAAA=" ChangeKey="CQAAABYAAADIQB5ZucBgRbu5MlIMCmzKAA9FrxKm" /></t:Message><t:Message><t:ItemId Id="AAAYAERUZXN0QGJpbGxpbmdzY2xpbmljLm9yZwBGAAAAAAAi8z5HQIgMRbIDKl6r1kyVBwDIQB5ZucBgRbu5MlIMCmzKAA8/RX7yAADIQB5ZucBgRbu5MlIMCmzKAA8/RYVXAAA=" ChangeKey="CQAAABYAAADIQB5ZucBgRbu5MlIMCmzKAA8/RZFM" /></t:Message></t:Items></m:RootFolder></m:FindItemResponseMessage></m:ResponseMessages></m:FindItemResponse></soap:Body></soap:Envelope>
ozntz
toooooooooooooooooooooooooooooooooo
Didn't find an answer to this problem but I ran across cURL. Converted what I have so far and it is working great.