Access Exchange Web Services with PHP and cURL

后端 未结 3 1503
感动是毒
感动是毒 2020-12-29 10:04

Hello,

I am currently writing a client to access a Microsoft Exchange server and read contacts, appointments etc. from it.

Through days of searching I\'ve be

3条回答
  •  时光取名叫无心
    2020-12-29 10:53

    If you initialize your soap client properly, you should be able to preform any requests requests this way:

    $curl = curl_init($location); //'https://'.$server_address.'/EWS/Exchange.asmx'
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); //valid soap headers with keep-alive
    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_USERPWD, $user.':'.$password);
    $response = curl_exec($curl);
    

    As to your code, try commenting out following line:

    curl_setopt( $curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM );
    

    Also take a look wherever this wrapper works on your setup: http://ewswrapper.lafiel.net/ If it does, take a look at SOAP classes used there - it uses php built-in as base.

    Why can't you store wsdl file locally anyways?


    UPDATE:

    Ok, I played around with this in my Debian box and this works for me flawlessly:

    $domain = 'xxxxxx';
    $user = 'xxxxxx';
    $password = 'xxxxxx';
    $ch = curl_init('https://'.$domain.'/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, 0);
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$password);
    $response = curl_exec($ch);
    $info = curl_getinfo( $ch );
    $error =  curl_error ($ch);
    print_r(array($response,$info,$error));
    

    returns

    Array
    (
        [0] => 
    
        [1] => Array
            (
                [url] => xxxxx/EWS/Services.wsdl
                [content_type] => text/xml
                [http_code] => 200
                [header_size] => 250
                [request_size] => 147
                [filetime] => -1
                [ssl_verify_result] => 0
                [redirect_count] => 0
                [total_time] => 0.60574
                [namelookup_time] => 0.165249
                [connect_time] => 0.268173
                [pretransfer_time] => 0.474009
                [size_upload] => 0
                [size_download] => 55607
                [speed_download] => 91800
                [speed_upload] => 0
                [download_content_length] => 55607
                [upload_content_length] => 0
                [starttransfer_time] => 0.580931
                [redirect_time] => 0
                [certinfo] => Array
                    (
                    )
    
                [redirect_url] => 
            )
    
        [2] => 
    )
    

提交回复
热议问题