我最近开始使用PHP查找Web服务调用。 我无法使用以下相当简单的代码段,而Web服务会返回异常。
<?php
$client = new SoapClient("http://www.webservicex.net/geoipservice.asmx?wsdl");
print($client->__soapCall("GetGeoIP", array('IP' => '83.251.30.62')));
?>
我也尝试过更简单的$client->GetGeoIP('83.251.30.62');
,但它们都会产生相同的结果。
我的代码有问题吗? 以下例外:
Fatal error: Uncaught SoapFault exception: [soap:Server]
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: input at System.Text.RegularExpressions.Regex.IsMatch(String input) at
WebserviceX.Service.Adapter.IPAdapter.CheckIP(String IP) at
WebserviceX.Service.GeoIPService.GetGeoIP(String IPAddress) --- End of inner exception
stack trace --- in C:\Program Files (x86)\Apache Software
Foundation\Apache2.2\htdocs\isolda\test.php:16 Stack trace: #0 C:\Program Files
(x86)\Apache Software Foundation\Apache2.2\htdocs\isolda\test.php(16): SoapClient-
>__soapCall('GetGeoIP', Array) #1 {main} thrown in C:\Program Files (x86)\Apache
Software Foundation\Apache2.2\htdocs\isolda\test.php on line 16
答案 0 :(得分:2)
你应该写"IPAddress"
而不是'IP'
(在数组内)它会起作用。
$client = new SoapClient("http://www.webservicex.net/geoipservice.asmx?wsdl");
$result = $client->GetGeoIP(array("IPAddress" => "83.251.30.62")); //change was made here
echo $result->GetGeoIPResult->CountryName;