我获得了一个连接到Web服务的项目,执行某些操作。 Ther ewebservice需要身份验证。我获得了WSDL URL和证书副本。我无法使用soapClient成功连接到它,我收到此消息:
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://somesite.com/WebService.svc?WSDL' : failed to load external entity "https://somesite.com/WebService.svc?WSDL"
任何建议,为什么我收到这条消息?
这是我的代码:
$url = 'https://somesite.com/WebService.svc?WSDL';
$certFile = 'certificate/cert.crt';
$keyFile='certificate/cert.key';
$caFile='certificate/cert.csr';
$client = new SoapClient($url,
array(
'local_cert' => $certFile,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'soap_version' => SOAP_1_2,
'authentication'=> SOAP_AUTHENTICATION_DIGEST,
'ssl' => array(
'verifypeer' => false,
'verifyhost' => false,
'key' => $keyFile,
'cafile' => $caFile,
'allow_self_signed' => true
),
'https' => array(
'curl_verify_ssl_peer' => false,
'curl_verify_ssl_host' => false
),
'cache_wsdl' => WSDL_CACHE_NONE,
'cache_ttl' => 86400,
'trace' => true,
'exceptions' => true,
)
);
你知道失败的原因导致失败了吗?我尝试通过卷曲连接它,我可以成功连接。我对CURL的问题是我不知道如何调用web服务中的操作,如“logme”,“postMessages”等。
这是我的CURL代码:
$username = 'webservice';
$password ='abcdef';
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<logme>
<user>'.$username.'</user>
<pass>'.$password.'</pass>
</logme>
</soap:Body>
</soap:Envelope>';
$conn = curl_init();
curl_setopt( $conn, CURLOPT_SSLCERT, $certFile);
curl_setopt( $conn, CURLOPT_URL, $url );
curl_setopt( $conn, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $conn, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $conn, CURLOPT_FOLLOWLOCATION,true );
curl_setopt( $conn, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt( $conn, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $conn, CURLOPT_SSLKEY, $keyFile);
curl_setopt( $conn, CURLOPT_CAINFO, $caFile);
curl_setopt( $conn, CURLOPT_SSLCERT, $certFile);
curl_setopt($conn, CURLOPT_POST, true );
curl_setopt($conn, CURLOPT_POSTFIELDS, $xml_post_string);
$client = curl_exec($conn);
if($client === false)
{
echo 'Curl error: ' . curl_error($conn);
}
else
{
echo 'Congrats, no error!';
}
curl_close($conn);
执行CURL代码时,我会收到消息“恭喜,没有错误!”。所以我的问题是,在成功连接之后。我不知道如何调用WSDL的操作或向服务发送请求。有什么建议吗?
我有关于curl的更新,这是我收到的错误消息
“HTTP / 1.1 415无法处理消息,因为内容类型 'text / xml; charset =“utf-8”'不是预期的类型 “应用程序/肥皂+ xml的;字符集= UTF-8' 。