繁体   English   中英

NTLM身份验证+ soap客户端+未收到响应

[英]NTLM authentication + soap client + response not received

我有以下代码来调用Sharepoint数据的NTLM身份验证:

class NTLMSoapClient extends SoapClient {
/**
 * Whether or not to validate ssl certificates
 *
 * @var boolean
 */

    function __construct($location, $user, $passwd)
    {
        //print '1';

        $headers = array(

            'Method: POST',

            'Connection: Keep-Alive',

            'User-Agent: PHP-SOAP-CURL',

            'Content-Type: text/xml; charset=utf-8',

            'SOAPAction: ""',
        );

        $request='';

        //$this->__last_request_headers = $headers;

        $ch = curl_init($location);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        curl_setopt($ch, CURLOPT_HTTPHEADER , $headers);
        //print '2';

        curl_setopt($ch, CURLOPT_POST , true );

        curl_setopt($ch, CURLOPT_POSTFIELDS , $request);

        curl_setopt($ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1);

        // the next option may or may not cause issues with non-XML documents
        //curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);

        curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$passwd);
        //print '3';

        // optional SSL verification
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        $response = curl_exec($ch);
        print $response;

        // TODO: Add some real error handling.
        // If the response if false than there was an error and we should throw
        // an exception.
        if ($response === false) {
            //print '5';
            throw new EWS_Exception(
              'Curl error: ' . curl_error($ch),
              curl_errno($ch)
            );
        }

        //print '6';

        return $response;
    }
}

调用如下:

try{
            $this->soapObject = new NTLMSoapClient( $this->wsdl, $this->spUser, $this->spPass);
        }catch(SoapFault $fault){
            //If we are unable to create a Soap Client display a Fatal error.
            throw new Exception("Unable to locate WSDL file.");
        }

响应以wsdl的形式出现。 为什么响应以wsdl的形式出现。 它应该像正常的肥皂客户端调用中那样返回我的肥皂客户端对象数组。

这是示例代码的非常简化的版本:

class NTLMSoapClient extends SoapClient {

    function __construct($location, $user, $passwd) {
        $ch = curl_init($location);
        $response = curl_exec($ch);
        print $response;
        return $response; 
    }
}

$this->soapObject = new NTLMSoapClient( $this->wsdl, $this->spUser, $this->spPass);

请注意以下几点:

  1. 与父SoapClient ,您将wsdl url作为第一个参数传递。
  2. 在构造函数中,将wsdl url映射到参数$location
  3. curl_init ,您传入$location (这是在实例化对象时传入的wsdl url)。
  4. 您将curl_exec()响应存储为$response
  5. 忽略print $resposne; 假设这是为了进行故障排除,那么对象构造函数的最后一个操作是将$response变量返回到实例化NTLMSoapClient类的变量。

考虑到以上所有...

一种。 您的类更多地充当函数,因为创建对象只会导致返回卷曲响应(该对象实际上不再是对象,而是包含响应的字符串)。 充其量可以认为是一种“静态构造函数”。

b。 设置为返回字符串的变量以后不能再调用NTLMSoapClient类的方法,因为它只是一个字符串。

C。 您总是传递wsdl url,因此响应始终是该URL返回的内容,即您通过curl请求请求的wsdl。

d。 除了实例化类的对象外,我认为构造函数不应该返回任何东西。

e。 本机SoapClient不返回任何内容,因此您应该尝试对扩展类进行建模,使其更接近父类。

F。 即使此方法确实有效(这意味着涉及OOP和PHP,但我不了解这涉及其中),您的示例也仅显示了NTLMSoapClient请求初始wsdl,而没有任何后续示例代码显示它调用了Web方法服务或其他任何东西,那么在示例代码中您期望wsdl以外的其他地方吗?

G。 最后,以积极的语气结束,我希望鼓励您继续朝着总体目标努力,您可以肯定知道的一件事是扩展类返回wsdl,这意味着您已通过NTLM成功向服务服务器进行身份验证,这是您目标的上半部分,如果我了解代码的概念和您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM