Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中创建Soap身份验证请求_Php_Soap - Fatal编程技术网

在PHP中创建Soap身份验证请求

在PHP中创建Soap身份验证请求,php,soap,Php,Soap,我是SOAP新手,尝试将其与PHP连接,但没有积极的结果。也许你能帮我一把 SOAP 1.2请求 POST /XXXservice.asmx HTTP/1.1 Host: XXX.prueba.com Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi=

我是SOAP新手,尝试将其与PHP连接,但没有积极的结果。也许你能帮我一把

SOAP 1.2请求

POST /XXXservice.asmx HTTP/1.1
Host: XXX.prueba.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetAcData xmlns="https://prueba.com/">
      <Userid>string</Userid>
      <Password>string</Password>
    </GetAcData>
  </soap12:Body>
</soap12:Envelope>
POST/XXXservice.asmx HTTP/1.1
主持人:XXX.prueba.com
内容类型:应用程序/soap+xml;字符集=utf-8
内容长度:长度
一串
一串
SOAP 1.2响应

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetAcDataResponse xmlns="https://prueba.com/">
      <XX>xml</GetAcDataResult>
    </GetAcDataResponse>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1200正常
内容类型:应用程序/soap+xml;字符集=utf-8
内容长度:长度
xml
我使用了以下代码,但收到了以下消息:

SOAP-ERROR:分析WSDL:无法从“”加载:标记html第3行中的数据过早结束


首先,您需要Web服务的端点url,它为您提供wsdl内容。正如@camelswittenincamelcase在他的评论中所写,您应该尝试
https://XXX.YYYY.com/XXXservice.asmx?wsdl
而不是
https://XXX.YYYY.com/XXXservice.asmx

接下来,您应该将所有soap客户机内容包装在一个try/catch块中,以便在发生错误时获得所有可能的异常和大部分信息

try {
    $client = new \SoapClient(
        'https://XXX.YYYY.com/XXXservice.asmx?wsdl',
        [
            'cache_wsdl' => WSDL_CACHE_NONE,
            'exceptions' => true,
            'soap_version' => SOAP_1_2,
            'trace' => true,
        ]
    );
} catch (\SoapFault $fault) {
    echo "<pre>";
    var_dump($fault);
    echo "</pre>";

    echo "<pre>";
    var_dump($client->__getLastRequest());
    echo "</pre>";

    echo "<pre>";
    var_dump($client->__getLastResponse());
    echo "</pre>";
}
"; //获取Web服务的类型 回声“; }catch(\SoapFault$fault){ //错误处理 } 此外,您还可以为Web服务输出的函数和类型中提到的每个复杂类型编写数据对象。您可以在实例化soap客户端时向选项数组添加类映射,以便在相应的数据对象中自动解析每个响应和请求。soap客户端类映射的工作原理如下:在php文档中有详细说明


试试看。我相信你会自己得到的。

尝试使用
.asmx?wsdl
而不是
.asmx
try {
    $client = new \SoapClient(
        'https://XXX.YYYY.com/XXXservice.asmx?wsdl',
        [
            'cache_wsdl' => WSDL_CACHE_NONE,
            'exceptions' => true,
            'soap_version' => SOAP_1_2,
            'trace' => true,
        ]
    );
} catch (\SoapFault $fault) {
    echo "<pre>";
    var_dump($fault);
    echo "</pre>";

    echo "<pre>";
    var_dump($client->__getLastRequest());
    echo "</pre>";

    echo "<pre>";
    var_dump($client->__getLastResponse());
    echo "</pre>";
}
// getting the functions of your webservice
echo "<pre>";
var_dump( $client->__getFunctions() );
echo "</pre>";

// getting the types of your webservice
echo "<pre>";
var_dump( $client->__getTypes() );
echo "</pre>";
try {
    $client = new \SoapClient(
        'https://XXX.YYYY.com/XXXservice.asmx?wsdl',
        [
            'cache_wsdl' => WSDL_CACHE_NONE,
            'exceptions' => true,
            'soap_version' => SOAP_1_2,
            'trace' => true,
        ]
    );

    $data = new \stdClass();
    $data->Userid = 'YourUserId';
    $data->Username = 'YourUsername';

    $result = $client->GetAcData($data);

    // $result will be an object
    echo "<pre>";
    var_dump($result);
    echo "</pre>"; 
} catch (\SoapFault $fault) {
    // error handling
}