php SOAP:看起来我们没有 XML 文档

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

SOAP: looks like we got no XML document

phpsoapnusoap

提问by geoffs3310

I'm trying to create a web service but before I do I'm trying to get a simple example that I found on the internet to work first but I keep getting the following error:

我正在尝试创建一个 Web 服务,但在此之前,我正在尝试获取我在互联网上找到的一个简单示例,该示例首先可以工作,但我不断收到以下错误:

Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in C:\Documents and Settings\geoff\My Documents\Websites\jquery\index.php:20 Stack trace: #0 [internal function]: SoapClient->__call('getStockQuote', Array) #1 C:\Documents and Settings\geoff\My Documents\Websites\jquery\index.php(20): SoapClient->getStockQuote(Array) #2 {main} thrown in C:\Documents and Settings\geoff\My Documents\Websites\jquery\index.php on line 20

I am using nusoap v1.94

我正在使用 nusoap v1.94

My web service code looks like this:

我的网络服务代码如下所示:

function getStockQuote($symbol) {
$price = '1.23';
return $price;
}

require('nusoap.php');

$server = new soap_server();

$server->configureWSDL('stockserver', 'urn:stockquote');

$server->register("getStockQuote",
            array('symbol' => 'xsd:string'),
            array('return' => 'xsd:decimal'),
            'urn:stockquote',
            'urn:stockquote#getStockQuote');

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
                  ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

I know one cause is to have whitespace before or after your php tags in your server script but thats not the case. It has been driving me mad for hours! Any help would be much appreciated.

我知道一个原因是在您的服务器脚本中的 php 标签之前或之后有空格,但事实并非如此。它已经让我发疯了几个小时!任何帮助将非常感激。

采纳答案by rik

A byte order mark (BOM) would have the same effect as whitespace before the php tags. Hereyou find a PHP snippet to detect and remove a BOM. Be sure to configure you editor to not insert the BOM again.

字节顺序标记 (BOM) 与 php 标签前的空格具有相同的效果。 在这里,您可以找到用于检测和删除 BOM 的 PHP 代码段。请确保将您的编辑器配置为不再插入 BOM。

回答by mvsagar

Pretty late but adding my fix to benefit of others. I have got similar error when I changed my Apache server from 2.2 to 2.4 and PHP 5.4.10 to 5.6.18 on windows. Client app used php 5.6.1. To fix the problem, I have done the following:

很晚了,但添加了我的修复程序以造福他人。在 Windows 上将 Apache 服务器从 2.2 更改为 2.4 并将 PHP 5.4.10 更改为 5.6.18 时,我遇到了类似的错误。客户端应用程序使用 php 5.6.1。为了解决这个问题,我做了以下事情:

  1. Passed SOAP version parameter to SoapClient:

    'soap_version' => SOAP_1_1

  2. On the server php.ini configuration file I have added:

    always_populate_raw_post_data = -1

  1. 将 SOAP 版本参数传递给 SoapClient:

    'soap_version' => SOAP_1_1

  2. 在我添加的服务器 php.ini 配置文件上:

    always_populate_raw_post_data = -1

回答by Benj

A bit late, but this kinda error is often caused by server-side (SOAP sense) problem :

有点晚了,但是这种错误通常是由服务器端(SOAP 感知)问题引起的:

  • print/echo content
  • rik's answer too
  • mistake (eg I was currently having this error because of a miswritten filename in an include, generating an include error instead of executing the script...)
  • bad parameter in SOAP server
  • not the same compression level both sides (if compression used)
  • 打印/回声内容
  • rik的回答也是
  • 错误(例如,由于包含中的文件名写错,我当前遇到此错误,生成包含错误而不是执行脚本......)
  • SOAP 服务器中的错误参数
  • 两侧的压缩级别不同(如果使用压缩)

This message just inform you that the SOAP client did not receive well-formatted XML (eg. an error message instead of XML).

此消息只是通知您 SOAP 客户端没有收到格式正确的 XML(例如,错误消息而不是 XML)。

回答by Andrei Zhamoida

This error appears also if a soap XML response contains special Unicode characters. In my case it was REPLACEMENT CHARACTER (U+FFFD).

如果soap XML 响应包含特殊的Unicode 字符,也会出现此错误。就我而言,它是 REPLACEMENT CHARACTER ( U+FFFD)。

In details, inner function of the SoapClient xmlParseDocumentsets xmlParserCtxtPtr->wellFormedproperty as falseafter parsing. It throws soap fault with looks like we got no XML document.

具体来说,SoapClient 的内部函数xmlParseDocumentxmlParserCtxtPtr->wellFormed属性设置为false解析后。它抛出肥皂错误looks like we got no XML document

https://github.com/php/php-src/blob/master/ext/soap/php_packet_soap.c#L46

https://github.com/php/php-src/blob/master/ext/soap/php_packet_soap.c#L46

回答by Ipsita Rout

set always_populate_raw_post_data = -1in php.ini file (by removing the ;) and then restart the server. It worked fine for me.

always_populate_raw_post_data = -1在 php.ini 文件中设置(通过删除;)然后重新启动服务器。它对我来说很好。

回答by Kus

I received this error when I was interacting with the Magento API which was loading a model, and it was throwing a warning before outputting the xml response which was causing the error.

我在与加载模型的 Magento API 交互时收到此错误,并且在输出导致错误的 xml 响应之前抛出警告。

To fix it you can simply turn off warnings on the API function: error_reporting(0);

要修复它,您只需关闭 API 函数上的警告: error_reporting(0);

回答by Vrian7

Another possible solution...

另一种可能的解决方案......

I had the same problem, I was getting crazy. The solution was simple. Verifying my server.. cause it is a server error. My error was that i had put "rcp" instead of "rpc".

我有同样的问题,我快疯了。解决办法很简单。验证我的服务器.. 因为它是一个服务器错误。我的错误是我放了“rcp”而不是“rpc”。

回答by borodatych

As far as I understand, the error of the SOAP parser when it comes invalid XML.

据我了解,SOAP 解析器在 XML 无效时的错误。

As it was with me.

就像我一样。

  1. Turn on the display of the error
  2. performed in try-catch and in the catch call __getLastResponse
  3. I catch another error:
  1. 打开错误显示
  2. 在 try-catch 和 catch 调用中执行 __getLastResponse
  3. 我发现另一个错误:

Warning: simplexml_load_string(): Entity: line 1: parser error : xmlParseCharRef: invalid xmlChar value 26 in

警告:simplexml_load_string():实体:第 1 行:解析器错误:xmlParseCharRef:无效的 xmlChar 值 26

  1. The first patient was PHP5.3. Once run the script on the PHP5.4, became more informative error - I swear on an invalid character, because of which, presumably, and fell SOAP parser.
  1. 第一位患者是PHP5.3。一旦在 PHP5.4 上运行脚本,就会出现更多信息错误 - 我发誓一个无效的字符,因此,大概是 SOAP 解析器。

As a result, I obtained the following code:

结果,我得到了以下代码:

$params = array(...);
try
{
    $response = $client->method( $params );
}
catch(SoapFault $e)
{
    $response = $client->__getLastResponse();
    $response = str_replace("&#x1A",'',$response); ///My Invalid Symbol
    $response = str_ireplace(array('SOAP-ENV:','SOAP:'),'',$response);
    $response = simplexml_load_string($response);
}

If someone will tell in the comments what a symbol, I will be grateful.

如果有人会在评论中说出什么是符号,我将不胜感激。

回答by Boush

Try to look into your server log. If you use nginx, please look into /var/log/nginx/error.log. if "Permission denied" pop up, please change related dir owner. Hope it will work.

尝试查看您的服务器日志。如果您使用 nginx,请查看 /var/log/nginx/error.log。如果弹出“权限被拒绝”,请更改相关目录所有者。希望它会起作用。