2009-06-27 14 views
1

Alle,Aufruf eines Web-Service von PHP?

Atlast hatte unseren Admin das PEAR SOAP-Modul auf unserem Apache-Server installieren. Wenn ich jetzt den folgenden Code ausprobiere - gibt es mir einen Fehler "HTTP Bad Request". Kann jemand helfen?

<html> 
<body> 
<?php 
/* Include PEAR::SOAP's SOAP_Client class: */ 
require_once('SOAP/Client.php'); 
$zip = $_REQUEST['zip']; 
?> 

<form action="wszip.php" method="post"> 
<table cellspacing="10" bgcolor="CadetBlue"> 
<tr> 
<td><B>Enter Zip Code : </B><input type="text" name="zip" /></td> 
<td></td> 
<td><input type="Submit" value="Find It!"/></td> 
</tr> 
</table> 
<BR><BR><BR><BR> 
</form> 

<?php 
if($zip != "") 
{ 
    $wsdl_url = "http://www.webservicex.net/uszip.asmx?WSDL"; 
    $wsdl  = new SOAP_WSDL($wsdl_url); 
    $client = $wsdl->getProxy(); 
    $params = array('USZip' => $zip); 
    $response = $client->GetInfoByZIP($params); 
    echo $response; 
} 
?> 

</body> 
</html> 

Danke.

+0

Geben Sie Zip =:
getProxy(); \t $ params = array ('USZip' => $ zip); \t $ response = $ client-> GetInfoByZIP ($ params); \t Echo $ Antwort; } ?> – thezone

Antwort

2

Das wäre

$client = $wsdl->getProxy(); 
// don't wrap it into another array. 
// $params = array('USZip' => $zip); 
$response = $client->GetInfoByZIP($zip); 
var_dump($response);
, aber bevor ich irgendwelche Ergebnisse sehe, ist mein Bildschirm mit den Meldungen "PHP veraltet:" und "PHP Strict Standards: Nicht-statische Methode ..." überflutet. Ich würde lieber die soap extension
<?php 
echo PHP_VERSION, ' ', PHP_OS, "\n"; 
$client = new SoapClient(' http://www.webservicex.net/uszip.asmx?WSDL '); 
$response = $client->GetInfoByZIP(array('USZip'=>'10006')); 
var_dump($response);
verwenden, leider ist die Antwort als
<s:element minOccurs="0" maxOccurs="1" name="GetInfoByZIPResult"> 
    <s:complexType mixed="true"> 
     <s:sequence> 
      <s:any/> 
     </s:sequence> 
    </s:complexType> 
</s:element>
definiert, was grob übersetzt "die Antwort wird ... etwas" bedeutet, d. H. Sie müssen das XML "manuell" parsen.
<?php 
echo PHP_VERSION, ' ', PHP_OS, "\n"; 
$client = new SoapClient(' http://www.webservicex.net/uszip.asmx?WSDL '); 
$response = $client->GetInfoByZIP(array('USZip'=>'10006'));

$doc = new SimpleXMLElement($response->GetInfoByZIPResult->any); echo 'City: ', $doc->Table->CITY[0];

druckt
5.3.0RC4 WINNT 
City: New York

+0

Yeah .. das Element hat zu dem lächerlichsten Teil der gesamten SOAP-Spezifikation zu sein. – troelskn

Verwandte Themen