Web Service URL in SoapClient and SOAP-ERROR: Parsing WSDL error

Web Service URL in SoapClient and SOAP-ERROR: Parsing WSDL error

有一个 Web 服务 URL,其中 returns 一个国家/地区的城市详细信息。我可以使用 GET 方法通过直接 Http 请求在浏览器中访问此 Web 服务 URL 并且工作正常:

[Snip:我用 example]

更改了我的实际域名
http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username><Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData><ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>

但是当我尝试通过 SoapClient 访问以上 URL 时:

/* Line 36 */
$cities = new SoapClient("http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username><Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData><ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>");

出现以下错误:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
Couldn't find <definitions> in 'http://alpha.example.com/WSV2/StaticData.php?xml=
<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username>
<Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData>
<ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>'
in /srv/www/htdocs/test/inc/client.php:36 Stack trace: #0 /srv/www/htdocs/test/
inc/client.php(36): SoapClient->SoapClient('http://alpha.ex...') #1 /srv/www/
htdocs/ortmas/index.php(6): InitData->getCities(67) #2 {main} thrown in /srv/
www/htdocs/test/inc/client.php on line 36

您必须将 URL 传递给 WSDL,而不是实际调用本身。

例如:

$cities = new SoapClient("http://alpha.example.com/WSV2/StaticData.wsdl");

如果 url 在您的浏览器上有效,您可以尝试在 PHP 中执行以下操作:

$url = "http://alpha.example.com/WSV2/StaticData.php?xml=<StaticDataRequest><Header><Code>TT4533</Code><Username>skyman211</Username><Password>ammkj43</Password></Header><Body><GetStaticData>cities</GetStaticData><ExtraParams><CountryCode>67</CountryCode></ExtraParams></Body></StaticDataRequest>";  

$data = file_get_contents($url);