php soapclient wsdl SOAP-ERROR:解析 WSDL:无法加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33976391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:41:22  来源:igfitidea点击:

php soapclient wsdl SOAP-ERROR: Parsing WSDL: Couldn't load from

phpweb-servicessoapwsdl

提问by Erick

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

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

 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

我正在尝试使用带有类似 URL 的 SOAP API

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

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

http://clemdemo.com/test.wsdl

In PHP I use the code below

在 PHP 中,我使用下面的代码

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.

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

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

另外,我尝试通过在线 WSDL http://wsdlbrowser.com向 API 使用(发送请求)它可以工作,但是在使用 PHP 的代码上它失败了

回答by Michael Pedersen

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.

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

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

禁用Kaii 此处描述的证书验证,或者更好地让您的提供商修复他们的证书。

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);

回答by Tunde Pizzle

The error message appears to say that your app is not able to read our WSDL. Try opening a browser from the same machine on which your app is running and see if you can access the WSDL address at https://sampleurl.com/MerchantQueryService.asmx?WSDL.

错误消息似乎表明您的应用程序无法读取我们的 WSDL。尝试从运行您的应用程序的同一台机器上打开浏览器,看看您是否可以访问https://sampleurl.com/MerchantQueryService.asmx?WSDL 上的 WSDL 地址。

If not - you have a network/firewall/Anti Virus problem. (in case)

如果没有 - 您有网络/防火墙/防病毒问题。(如果)

If you can access this address from a browser - is your app still experiencing this problem? then check any app that could be hindering your firewall.(Anti virus are most probable cause)

如果您可以从浏览器访问此地址 - 您的应用程序是否仍然遇到此问题?然后检查任何可能阻碍防火墙的应用程序。(反病毒是最可能的原因)

回答by ppostma1

  • Better diagnostics can be performed with: libxml_get_last_error();
  • Could have cached a bad response, set 'cache_wsdl' => WSDL_CACHE_NONE when initating the object
  • if you skip cache, and get this in your libxml error:

    LibXMLError Object ( [level] => 1 [code] => 1549 [column] => 0 [message] => failed to load external entity "URL" [file] => [line] => 0 )

  • 可以使用以下命令执行更好的诊断: libxml_get_last_error();
  • 可能缓存了错误的响应,在初始化对象时设置 'cache_wsdl' => WSDL_CACHE_NONE
  • 如果你跳过缓存,并在你的 libxml 错误中得到这个:

    LibXMLError 对象([level] => 1 [code] => 1549 [column] => 0 [message] => 无法加载外部实体“URL”[file] => [line] => 0)

With no description on Ubuntu, then its not pulling the file period. You just got hit with the Ubuntu update. Wave them the bronx salute and reboot.

没有关于 Ubuntu 的描述,那么它不会拉文件周期。您刚刚获得了 Ubuntu 更新。向他们挥手布朗克斯致敬并重新启动。