標籤:style class blog code java http
下面是我以前對Php的soap介面進行抓包分析出的結果,這個分析在當服務端或者用戶端的Php沒有安裝soap模組時,可以使用構建xml的方式實現相同的功能
服務端:
$data = $HTTP_RAW_POST_DATA;$data = file_get_contents(‘php://input‘);$server = new SoapServer(null, array(‘uri‘ => "http://abc-soap-duba/"));$server->addFunction("sendtask");$server->handle($data);function sendtask(){ return "ok";}
用戶端代碼
<?php $client = new SoapClient(null, array(‘location‘ => "http://api.abc.cn/taskserver.php", ‘uri‘ => "http://abc-soap-duba/")); $username="[email protected]"; $password=md5("123456"); $domain="www.abc.cn"; $pathsizelist="/images/ad2.gif,4846,/images/ad3.gif,5788,/images/ico01.gif,1089,/images/logo.gif,1605"; echo $client->sendtask($username,$password,$domain,$pathsizelist); ?>
用戶端發出的資料:
POST /b.php HTTP/1.1 Host: api.abc.cn Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.2 Content-Type: text/xml; charset=utf-8 SOAPAction: "http://abc-soap-duba/#sendtask" Content-Length: 766 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://abc-soap-duba/" 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:sendtask> <param0 xsi:type="xsd:string">[email protected]</param0> <param1 xsi:type="xsd:string">e10adc3949ba59abbe56e057f20f883e</param1> <param2 xsi:type="xsd:string">www.abc.cn</param2> <param3 xsi:type="xsd:string">/images/ad2.gif,4846,/images/ad3.gif,5788,/images/ico01.gif,1089,/images/logo.gif,1605</param3> </ns1:sendtask> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
當server中沒有改函數時返回的結果
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>Function ‘sendtasks‘ doesn‘t exist</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
當server中有該函數時的結果
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://abc-soap-duba/" 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:sendtaskResponse> <return xsi:type="xsd:string">ok</return> </ns1:sendtaskResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
end