【发布时间】:2019-03-28 18:37:25
【问题描述】:
我正在尝试将标头和正文传递给 SOAP 请求。由于错误的做法,我收到了连接错误。当我使用 SOAP UI 尝试相同的操作时,我得到了正确的响应。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:adp="http://abcddetails.com/">
<soapenv:Header>
<adp:UserIdentifierSoapHeaderIn>
<!--Optional:-->
<adp:UserName>USER1</adp:UserName>
<!--Optional:-->
<adp:Password>PASS</adp:Password>
</adp:UserIdentifierSoapHeaderIn>
</soapenv:Header>
<soapenv:Body>
<adp:getVehicleDetails>
<!--Optional:-->
<adp:request>
<adp:SystemCode>101</adp:SystemCode>
<!--Optional:-->
<adp:UserID>101</adp:UserID>
<!--Optional:-->
<adp:PlateInfo>
<adp:PlateNo>44444</adp:PlateNo>
<adp:PlateOrgNo>1</adp:PlateOrgNo>
<adp:PlateColorCode>48</adp:PlateColorCode>
<adp:PlateKindCode>1</adp:PlateKindCode>
<adp:PlateTypeCode>1</adp:PlateTypeCode>
<adp:PlateSourceCode>3</adp:PlateSourceCode>
</adp:PlateInfo>
</adp:request>
</adp:getVehicleDetails>
</soapenv:Body>
</soapenv:Envelope>
以下是我的代码:
<?php
echo "Hello world";
echo "ADDED the below two lines"
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$wsdl = "https://abcddetails.com/getSoapDetails.asmx?WSDL";
$client = new SoapClient($wsdl, array('trace'=>1));
$auth = array(
'Username'=>'USER1',
'Password'=>'PASS',
);
$header = new SOAPHeader($wsdl, 'UserIdentifierSoapHeaderIn', $auth);
$client->__setSoapHeaders($header);
echo "Header Passed... Body starts";
// web service input params
$request_param = array(
'getCarDetails' => array(
'request' => array(
'SystemCode' => 101,
'UserID' => 101),
'PlateInfo' => array(
'PlateNo' => 44444,
'PlateOrgNo' => 1,
'PlateColorCode' => 48,
'PlateKindCode' => 1,
'PlateTypeCode' => 1,
'PlateSourceCode' => 3 )
)
);
$responce_param = null;
try
{
$responce_param = $client->__soapCall('getCarDetails', ['parameters' => $request_param]);
}
catch (Exception $e)
{
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
print_r($responce_param);
?>
错误信息是
无法连接到主机
但如上所述,相同的 xml 请求正在通过 Soap UI 应用程序给出正确的响应。这里可能是什么问题?我怀疑 Header 分配,是这样,还是在其他地方?
【问题讨论】:
-
@DanielO,嗨,你能看看这个
-
Could not connect to host听起来像是网络/dns/防火墙问题。 -
也可能是代理或 ssl 相关问题(例如对等验证问题)。您是否通过proxy 连接到 SSL WebService?它是自签名的 ssl 证书吗?尝试禁用对等验证。
'stream_context'=> stream_context_create(array('ssl'=> array('verify_peer'=>false,'verify_peer_name'=>false))) -
谢谢@DanielO 我已经尝试过卷曲并且它工作得很好。没有连接问题。我已经替换了代码。我将添加代码,可能对其他人有帮助
标签: php soap wamp wampserver soap-client