php 如何摆脱“未捕获的 SoapFault 异常:[客户端] 看起来我们没有 XML 文档......”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2540438/
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 06:53:56  来源:igfitidea点击:

How to get rid of "Uncaught SoapFault exception: [Client] looks like we got no XML document in..." error

phpsoapwsdlweb-servicesnusoap

提问by Eedoh

I'm trying to develop business logic for a dynamic site using nusoap on server side (because I need wsdls, and PHP SOAP extension can't generate wsdls), and PHP SOAP extenstion on client side.

我正在尝试在服务器端使用 nusoap 为动态站点开发业务逻辑(因为我需要 wsdls,而 PHP SOAP 扩展无法生成 wsdls),并在客户端使用 PHP SOAP 扩展。

However, I can't get even login and getRole functions right. When i try to invoke client, I get following message

但是,我什至无法正确使用 login 和 getRole 函数。当我尝试调用客户端时,我收到以下消息

Uncaught SoapFault exception: [Client] looks like we got no XML document in [some paths]...

Wsdl does exist on server side, and client does read it (when I put wrong url for wsdl, I get an error).

Wsdl 确实存在于服务器端,并且客户端确实读取了它(当我为 wsdl 输入错误的 url 时,我收到错误消息)。

Can anyone help??

有人可以帮忙吗??

回答by Henrik Opel

It looks like your client receives some invalid XML - either the WSDL itself or the response returned by the server. Try to invoke the client with the traceoption set to TRUE and check the actual XML send/received via the __getLastRequest()and __getLastResponse()methods.

看起来您的客户端收到了一些无效的 XML - WSDL 本身或服务器返回的响应。尝试在trace选项设置为 TRUE 的情况下调用客户端,并检查通过__getLastRequest()__getLastResponse()方法发送/接收的实际 XML 。

回答by Ben

I just had a similar problem; turns out my service was echoing out some debug data. I removed all of the echolines and it worked fine.

我刚刚遇到了类似的问题;原来我的服务正在echo输出一些调试数据。我删除了所有的echo行,它工作正常。

回答by Ignacio Gutierrez

I have the same problem, and I solved with this:

我有同样的问题,我用这个解决了:

The server SOAP file in php has encode utf8 with BOM, causing apache send back the BOM mark (3 bytes) before the xml response.

php 中的服务器 SOAP 文件使用 BOM 对 utf8 进行编码,导致 apache 在 xml 响应之前发回 BOM 标记(3 个字节)。

Encode your php file soap server with utf8 WITH OUT BOM mark.

使用没有 BOM 标记的 utf8 对您的 php 文件soap服务器进行编码。

Ignacio Gutierrez Torrero

伊格纳西奥·古铁雷斯·托雷罗

回答by PHPst

Don't forget to use try/catch block:

不要忘记使用 try/catch 块:

try {
    var_dump($client->foo());
} catch (Exception $e) {
    echo($client->__getLastResponse());
    echo PHP_EOL;
    echo($client->__getLastRequest());
}

回答by Ratsitobaina Friedrich

Just use trim() for you args.

只需为您的参数使用 trim() 即可。

$objectRequette = trim($_POST['Requette']) ;
$client = new SoapClient(null, array(
    'location' => 'http://your.php',
    'uri'=>'your option',
));
$result = $client->__soapCall('Misyka', array("$objectRequettea"));

回答by Denwork

In my case, this error appeared when I included a script with blank lines after the "?>" label.

就我而言,当我在“?>”标签后包含一个带有空行的脚本时,会出现此错误。

Delete these lines solves the problem

删除这些行可以解决问题

回答by Tash Pemhiwa

Chances are you have some trailing whitespace at the end of your SOAPServer class. Please have a look at the following blog postfor more information: http://arnekroeger.blogspot.com/2011/02/php-soap-error-looks-like-we-got-no-xml.html

您可能在 SOAPServer 类的末尾有一些尾随空格。请查看以下博客文章以获取更多信息:http: //arnekroeger.blogspot.com/2011/02/php-soap-error-looks-like-we-got-no-xml.html

回答by Shuvankar Sarkar

Some times a BOM can generate some extra characters which creates this type of problem.

有时,BOM 会生成一些额外的字符,从而产生此类问题。

To detect if there is any UTF BOM see this link.

要检测是否有任何 UTF BOM,请参阅此链接

回答by Grazziani

I have a way to solve this problem. This isn't a pretty solution, but it works...

我有办法解决这个问题。这不是一个很好的解决方案,但它有效......

How I can't do any change in my mantis server, I decided do this...

我怎么不能对我的螳螂服务器做任何改变,我决定这样做......

First I have to silence SoapFault:

首先,我必须使 SoapFault 静音:

try {
    $client = new SoapClient('http://www.mymantisaddress.com/api/soap/mantisconnect.php?wsdl', array('trace'=> 1, 'exceptions' => 0));
    $result = $client->__soapCall($function_name, $args);
} catch (SoapFault $e) {
    //$result = array(
    //    'erro' => $e->faultstring
    //);
}

Second, I've noted that there was this three trailing control char in begin of my string, so I've removed it:

其次,我注意到我的字符串开头有这三个尾随控制字符,因此我将其删除:

$str = substr($client->__getLastResponse(), 3) . "pe>";
print $str;

Third, I've to put "pe>" in the end of my string, cause it was incomplete.

第三,我必须将“pe>”放在字符串的末尾,因为它不完整。

回答by Mostafa

I have same problem.my problem solved by set always_populate_raw_post_datato -1on php.ini.

我有同样的问题。我的问题通过在 php.ini 上设置always_populate_raw_post_data为解决了-1

I find out this by adding "trace"=>1,"exceptions"=>1 on options and use try catchand get __getLastRequest()and __getLastResponse()

我通过在选项上添加 "trace"=>1,"exceptions"=>1 并使用try catch和获取__getLastRequest()__getLastResponse()