Reputation: 33
All,
Atlast had our admin install the PEAR SOAP module on our apache server. Now when i try the following code - it is giving me an error "HTTP Bad Request". Can anyone help?
<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>
Thanks.
Upvotes: 1
Views: 1114
Reputation: 96159
That would be
$client = $wsdl->getProxy();
// don't wrap it into another array.
// $params = array('USZip' => $zip);
$response = $client->GetInfoByZIP($zip);
var_dump( $response );
but before seeing any results my screen is flooded with "PHP Deprecated:" and "PHP Strict Standards: Non-static method ..." messages. I'd rather use the 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);
unfortunately the response is defined as<s:element minOccurs="0" maxOccurs="1" name="GetInfoByZIPResult"> <s:complexType mixed="true"> <s:sequence> <s:any/> </s:sequence> </s:complexType> </s:element>which roughly translated means "the response will be ...something", i.e. you have to parse the xml "manually".
<?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];
prints5.3.0RC4 WINNT City: New York
Upvotes: 2