php soap 错误 “looks like we got no XML document”
今天在想使用soap开发相关接口给合作的公司调用,但是遇到了这个错误。排查了很久,在google也查了很久,但都不是我所遇到的问题。不过我最终错误发现跟soapserver传输的数据量的大小有关系(不知道这个描述是否恰当)。当我从数据库取10条数据,那么就可以很容易的使用soapclient获取到数据,但是当我从数据库里查询1000条数据的时候就会报错了(“Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in……”)!如果我直接运行person.class.php程序是可以显示完整的xml文档的。这根服务器的环境配置会有关系吗?我对于soap认识并不深,也只是现学现卖。希望有经验的前辈们可以指点一二。多谢了!
以下是我的程序代码:
<?php //person.class.php文件 class person { public function getInfo() { $strGetList = 'SELECT * FROM information LIMIT 100'; $GLOBALS['le']->query($strGetList); $results = array(); $xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; $xmlString .="<data>\n"; while( $rows = $GLOBALS['le']->fetch_assoc() ) { $results[] = $rows; } foreach($results as $key=>$val) { $xmlString .="<rec id="UU{$key}">\n"; foreach($val as $k=>$v ) { if(strlen($v)>0) { $v = htmlspecialchars($v); $xmlString .=" <uu>$v</uu>{$k}>\n"; } } $xmlString .="</rec>\n"; } $xmlString .="</data>\n"; return $xmlString; } } //$p = new person; //echo $p->getInfo();//经测试xml中可以显示所有数据 --- 分割线 --- <?php //server.php文件 include("person.class.php"); $server = new SoapServer(null,array('uri'=>'abcd','encoding'=>'UTF-8')); $server->setClass('person'); $server->handle(); --- 分割线 --- <?php //client.php文件 try{ $soap = new SoapClient(null,array( 'location'=>'http://192.168.1.126:102/server.php', 'uri'=>'abcd', 'encoding' => 'UTF-8', )); $s1 =$soap->__soapCall('getInfo',array()); echo $s1; } catch(Exction $e) { echo $e->getMessage(); }
回复内容:
今天在想使用soap开发相关接口给合作的公司调用,但是遇到了这个错误。排查了很久,在google也查了很久,但都不是我所遇到的问题。不过我最终错误发现跟soapserver传输的数据量的大小有关系(不知道这个描述是否恰当)。当我从数据库取10条数据,那么就可以很容易的使用soapclient获取到数据,但是当我从数据库里查询1000条数据的时候就会报错了(“Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in……”)!如果我直接运行person.class.php程序是可以显示完整的xml文档的。这根服务器的环境配置会有关系吗?我对于soap认识并不深,也只是现学现卖。希望有经验的前辈们可以指点一二。多谢了!
以下是我的程序代码:
<?php //person.class.php文件 class person { public function getInfo() { $strGetList = 'SELECT * FROM information LIMIT 100'; $GLOBALS['le']->query($strGetList); $results = array(); $xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; $xmlString .="<data>\n"; while( $rows = $GLOBALS['le']->fetch_assoc() ) { $results[] = $rows; } foreach($results as $key=>$val) { $xmlString .="<rec id="UU{$key}">\n"; foreach($val as $k=>$v ) { if(strlen($v)>0) { $v = htmlspecialchars($v); $xmlString .=" <uu>$v</uu>{$k}>\n"; } } $xmlString .="</rec>\n"; } $xmlString .="</data>\n"; return $xmlString; } } //$p = new person; //echo $p->getInfo();//经测试xml中可以显示所有数据 --- 分割线 --- <?php //server.php文件 include("person.class.php"); $server = new SoapServer(null,array('uri'=>'abcd','encoding'=>'UTF-8')); $server->setClass('person'); $server->handle(); --- 分割线 --- <?php //client.php文件 try{ $soap = new SoapClient(null,array( 'location'=>'http://192.168.1.126:102/server.php', 'uri'=>'abcd', 'encoding' => 'UTF-8', )); $s1 =$soap->__soapCall('getInfo',array()); echo $s1; } catch(Exction $e) { echo $e->getMessage(); }
从SoapClient的异常"[Client] looks like we got no XML document"来看应该是响应有问题,所以首要的是查看响应消息是什么,有几种方案可以协助你定位问题:
- 简单一点的,你可以用SoapUI,查看响应是否真的有问题?是否没有响应?
- Geek一点的,自制一个模拟客户端来检查响应消息,普通的SOAP协议并不难,只需用HTTP协议POST一小段XML给Server就行,代码量应该在20行以内
- 我平时常用一点的,因为SOAP是走HTTP传输协议的,因此可以抓取整个HTTP Response,检查其内容是否符合XML格式。抓取方式可以用tcpdump(Linux命令行)或HTTPTracer(Java跨平台,使用方便,我的最爱)
- 直接一点的,查看SoapClient.php的源码,我没记错的话代码量挺小的,查找字符串“looks like we got no XML document”,然后往回找到XML解析那段,在解析前输出原始内容看看到底响应内容出现了什么问题
别用soap,把接口发给你的数据dump出来看看。估计是网络传输出了啥问题,数据没抓全,xml不完整,没法解析。
你问题解决了吗?求指导

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
