从php调用Web服务?

时间:2009-06-21 19:11:39

标签: php web-services

我试图从PHP网页上调用公开的Web服务。

网络服务是:http://www.webservicex.net/uszip.asmx?WSDL


我的代码:

<html>
<body>
<?php
$zip = $_REQUEST['zip'];
echo 'zip is'.$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 = "http://www.webservicex.net/uszip.asmx?WSDL";
    $client = new soapclient($wsdl, true);
    $response = $client->GetInfoByZIP($zip);
}
?>
</body>
</html>

1 个答案:

答案 0 :(得分:7)

您输入的邮政编码不正确,您的构造函数语法也不正确。请改用此语法:

$wsdl = "http://www.webservicex.net/uszip.asmx?WSDL";
$client = new soapclient($wsdl);
$response = $client->GetInfoByZIP(array('USZip' => $zip));

我刚试过它,它运行正常。文档为here