<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="GAAuth" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:reverseResponse><return xsi:type="xsd:string"></return></ns1:reverseResponse></SOAP-ENV:Body></SOAP-ENV:Envelo
这是我用PHP5.2 SoapClient返回的LastResponse结果, 我抓包看HTTP返回的数据是完整的,但是getLastResponse却是少了最后三个字节pe>, 所以就报SoapFault异常. 不管是服务端还是客户端的网卡抓包看, HTTP返回数据都是完整的,没有缺那三个字节.下面贴上代码
server的
<?
include_once('soapfunc.php');
$soap = new SoapServer(null,array('uri'=>"GAAuth"));
$soap->addFunction('reverse');
$soap->addFunction('add2numbers');
$soap->addFunction('gettime');
//$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();
?> 客户端的
<?
try
{
$client = new SoapClient
(null,
array
(
'location' =>"http://172.16.200.8:82/GAAuth/soapserver.php",
'uri' => "GAAuth",
//'style' => SOAP_RPC,
//'use' => SOAP_ENCODED,
"trace"=>1,
"exceptions"=>0
)
);
$str = "This string will be reversed";
$reversed = $client->reverse($str);
//var_dump($client->__getLastResponseHeaders());
//var_dump($client->__getLastResponse());
$strDump=$client->__getLastResponse();
echo $strDump;
echo "\n\n";
$strDump2="aaaa " . $client->__getLastResponse() . " bbbb";
echo $strDump2;
echo "The system time is: ",$client->gettime();
echo "If you reverse '",$str,"', you get '",$reversed,"'";
$n1=20;
$n2=33;
$sum = $client->add2numbers($n1,$n2);
echo "If you try ",$n1,"+",$n2,", you will get ",$sum,"";
}
catch (SoapFault $fault)
{
echo "Fault! code:",$fault->faultcode,", string: ",$fault->faultstring;
}
?> 都是最简单的测试webservice的代码,咋这么怪呢
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="GAAuth" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:reverseResponse><return xsi:type="xsd:string"></return></ns1:reverseResponse></SOAP-ENV:Body></SOAP-ENV:Envelo
这是我用PHP5.2 SoapClient返回的LastResponse结果, 我抓包看HTTP返回的数据是完整的,但是getLastResponse却是少了最后三个字节pe>, 所以就报SoapFault异常. 不管是服务端还是客户端的网卡抓包看, HTTP返回数据都是完整的,没有缺那三个字节.下面贴上代码
server的
<?
include_once('soapfunc.php');
$soap = new SoapServer(null,array('uri'=>"GAAuth"));
$soap->addFunction('reverse');
$soap->addFunction('add2numbers');
$soap->addFunction('gettime');
//$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();
?> 客户端的
<?
try
{
$client = new SoapClient
(null,
array
(
'location' =>"http://172.16.200.8:82/GAAuth/soapserver.php",
'uri' => "GAAuth",
//'style' => SOAP_RPC,
//'use' => SOAP_ENCODED,
"trace"=>1,
"exceptions"=>0
)
);
$str = "This string will be reversed";
$reversed = $client->reverse($str);
//var_dump($client->__getLastResponseHeaders());
//var_dump($client->__getLastResponse());
$strDump=$client->__getLastResponse();
echo $strDump;
echo "\n\n";
$strDump2="aaaa " . $client->__getLastResponse() . " bbbb";
echo $strDump2;
echo "The system time is: ",$client->gettime();
echo "If you reverse '",$str,"', you get '",$reversed,"'";
$n1=20;
$n2=33;
$sum = $client->add2numbers($n1,$n2);
echo "If you try ",$n1,"+",$n2,", you will get ",$sum,"";
}
catch (SoapFault $fault)
{
echo "Fault! code:",$fault->faultcode,", string: ",$fault->faultstring;
}
?> 都是最简单的测试webservice的代码,咋这么怪呢
我只在服务端加了个reverse方法进行测试.
结果desrever eb lliw gnirts sihT aaaa <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="GAAuth" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:reverseResponse><return xsi:type="xsd:string">desrever eb lliw gnirts sihT</return></ns1:reverseResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> bbbb
多了四个字节, 但header里面的长度并没有+4, 导致最后丢了关键的pe/>我换个apache试试看
至于为什么三个不可见字符能让apache返回数据混乱, 就不得而知了. 给大家散分, 参与者皆有份