PHP SoapClient-异常,我做错了什么?

发布于 2024-12-27 20:13:43 字数 1211 浏览 0 评论 0原文

我最近开始寻找使用 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

I´ve recently started looking a web service calls using PHP.
I can´t get the following rather simple snippet to work, instead the web service returns an exception.

<?php
$client = new SoapClient("http://www.webservicex.net/geoipservice.asmx?wsdl");
print($client->__soapCall("GetGeoIP", array('IP' => '83.251.30.62')));
?>

I´ve also tried the simpler $client->GetGeoIP('83.251.30.62'); but they both yield the same result.

Is there something wrong with my code?
Exception below:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽容 2025-01-03 20:13:43

您应该编写 "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;

You should write "IPAddress" instead of 'IP' (Inside the array) and it will work.

$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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文