本文介绍了php soapclient wsdl SOAP-ERROR:解析 WSDL:无法加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 stackoverflow 中搜索并查看了此处,但我还没有找到解决我的具体问题的方法.我不断收到错误

 SOAP-ERROR:解析 WSDL:无法从https://sampleurl.com/MerchantQueryService.asmx?WSDL"加载:无法加载外部实体https://sampleurl.com/MerchantQueryService.asmx?WSDL"

我正在尝试使用带有类似

的 URL 的 SOAP API

https://sampleurl.com/MerchantQueryService.asmx?WSDL

我在我的本地主机上运行 MAMP 并使用 Godaddy 共享主机,我已经尝试使用 wsdl 文件可以在这里找到

http://clemdemo.com/test.wsdl

在 PHP 中我使用下面的代码

error_reporting(-1);ini_set('display_errors', 'On');ini_set('soap.wsdl_cache_enabled', 0);echo "

";尝试 {$url = "https://sampleurl.com/MerchantQueryService.asmx?WSDL";$headers = ['主机:sampleurl.com','连接:保持活动','用户代理:PHP-SOAP/5.3.29','内容类型:文本/xml;字符集=utf-8','SOAPAction: "RequestTransaction"','内容长度:409'];$rq = [用户名" =>"username_here",密码" =>"password_here",referenceId" =>"3455566694",msisdn"=>"346774313"];尝试 {$cient = 新 SoapClient($url,['soap_version' =>肥皂_1_2,'例外' =>1、'cache_wsdl' =>WSDL_CACHE_NONE,'跟踪' =>1、'stream_context' =>stream_context_create(array('http' => array('header' => $headers)))]);打印_r($cient);}赶上(SoapFault $e){echo "\n故障代码:".$e->故障代码;echo "\nFault String: ".$e->faultstring;}

在我的 MAMP 本地主机上,我有 SOAP、openssl 和 curl.

另外,我尝试使用(发送请求)到带有在线 WSDL http://wsdlbrowser.com 的 API有效,但在使用 PHP 的代码上失败

解决方案

供应商经常会忽略他们的 SSL 证书,因此站点和服务最终会使用无效的证书 - 我怀疑这里就是这种情况.

禁用证书验证,如由 Kaii 在这里 或更好地获得您的提供商修复他们的证书.

您的代码可以/应该是这样的:

$url = "https://sampleurl.com/MerchantQueryService.asmx?WSDL ";$context = stream_context_create(数组('ssl' =>大批('verify_peer' =>错误的,'verify_peer_name' =>错误的,'allow_self_signed' =>真的)));$rq = [用户名" =>"username_here",密码" =>"password_here",referenceId" =>"3455566694",msisdn"=>"346774313"];$service = new SoapClient($url, array('stream_context' => $context));$service->RequestTransaction($rq);

I have googled and looked here in stackoverflow but I have not found a solution to my specific problem. I keep getting the error

 SOAP-ERROR: Parsing WSDL: Couldnt load from "https://sampleurl.com/MerchantQueryService.asmx?WSDL" : failed to load external entity "https://sampleurl.com/MerchantQueryService.asmx?WSDL"

I am trying to use a SOAP API with a URL like

https://sampleurl.com/MerchantQueryService.asmx?WSDL

I am running MAMP on my localhost and using godaddy shared hosting, I have tried on both with the wsdl file can be found here

http://clemdemo.com/test.wsdl

In PHP I use the code below

error_reporting(-1);
ini_set('display_errors', 'On');
ini_set('soap.wsdl_cache_enabled', 0);

echo "<pre>";

try {

$url     = "https://sampleurl.com/MerchantQueryService.asmx?WSDL ";
$headers = [
    'Host: sampleurl.com',
    'Connection: Keep-Alive',
    'User-Agent: PHP-SOAP/5.3.29',
    'Content-Type: text/xml; charset=utf-8',
    'SOAPAction: "RequestTransaction"',
    'Content-Length: 409'];

$rq = [
"userName" => "username_here",
"passWord" => "password_here",
"referenceId" => "3455566694",
"msisdn" => "346774313"];


try {

$cient = new SoapClient($url,
    [
    'soap_version' => SOAP_1_2,
    'exceptions' => 1,
    'cache_wsdl' => WSDL_CACHE_NONE,
    'trace' => 1,
    'stream_context' => stream_context_create(array('http' => array('header' => $headers)))
]);

print_r($cient);
} catch (SoapFault $e) {
    echo "\nFault Code: ".$e->faultcode;
    echo "\nFault String: ".$e->faultstring;
}

On my MAMP localhost i have SOAP,openssl and curl.

ALSO, I tried using (sending request) to the API with an online WSDL http://wsdlbrowser.com it WORKS but on code using PHP it fails

解决方案

It often happens that providers neglect their SSL certificates and hence the sites and services end up having an invalid certificates - I suspect this is the case here.

Disabling the certificate validation as described by Kaii here or even better get your provider to fix their certificate.

Your code could/should then be something like:

$url     = "https://sampleurl.com/MerchantQueryService.asmx?WSDL ";
$context = stream_context_create(array(
        'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
        )
));

$rq = ["userName" => "username_here",
       "passWord" => "password_here",
       "referenceId" => "3455566694",
       "msisdn" => "346774313"];

$service = new SoapClient($url, array('stream_context' => $context));
$service->RequestTransaction($rq);

这篇关于php soapclient wsdl SOAP-ERROR:解析 WSDL:无法加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 11:59