我正在尝试从交换中获取日历。但是交换返回403 http代码
$action='http://schemas.microsoft.com/exchange/services/2006/messages/FindItem';
$headers = array(
'Method: POST',
'Connection: Keep-Alive',
'User-Agent: PHP-SOAP-CURL',
'Content-Type: text/xml; charset=utf-8',
'SOAPAction: "'.$action.'"',
);
$ch = curl_init('https://www.outlook.com/EWS/Exchange.asmx');
$request = '<?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:Header><ns1:RequestServerVersion Version="Exchange2007"/></SOAP-ENV:Header><SOAP-ENV:Body><ns2:FindItem Traversal="Shallow"><ns2:ItemShape><ns1:BaseShape>Default</ns1:BaseShape></ns2:ItemShape><ns2:CalendarView StartDate="2012-06-12T15:18:34+03:00" EndDate="2014-06-12T15:18:34+03:00"/><ns2:ParentFolderIds><ns1:DistinguishedFolderId Id="calendar"/></ns2:ParentFolderIds></ns2:FindItem></SOAP-ENV:Body></SOAP-ENV:Envelope>';
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$password); //$user and $password are ok
$response = curl_exec($ch);
var_dump($response);
$i = curl_getinfo($ch);
print_r($i);
这段代码告诉我:
string(0) ""
Array
(
[url] => https://www.outlook.com/EWS/Exchange.asmx
[content_type] =>
[http_code] => 403
[header_size] => 746
[request_size] => 2021
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 1
[total_time] => 2.849341
[namelookup_time] => 3.8E-5
[connect_time] => 4.1E-5
[pretransfer_time] => 0.000162
[size_upload] => 693
[size_download] => 0
[speed_download] => 0
[speed_upload] => 243
[download_content_length] => 0
[upload_content_length] => 693
[starttransfer_time] => 2.663647
[redirect_time] => 0.18565
[redirect_url] =>
[primary_ip] => ......
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => .....
[local_port] => 42052
)
当我设置错误的用户或密码时,交换机给我401.当用户和密码正常时,交换给我403.问题出在哪里?