通过PHP访问SOAP


accessing SOAP via PHP

我有一个网站,它需要向另一台服务器发送请求并检索一些数据。我对SOAP一无所知,所以我需要一位专家的帮助。

这是第二台服务器给我的数据。我不知道从哪里开始,也不知道该怎么做,所以我很感激你的帮助。你能给我一个php代码的工作示例吗。

肥皂1.1

以下是SOAP 1.1请求和响应的示例。显示的占位符需要替换为实际值。

POST /Service1.asmx HTTP/1.1
Host: puanreport.retail.az
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/_find"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <_find xmlns="http://tempuri.org/">
      <par>string</par>
    </_find>
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <_findResponse xmlns="http://tempuri.org/">
      <_findResult>
        <bon>
          <Cari_Kod>string</Cari_Kod>
          <Puan>string</Puan>
        </bon>
        <bon>
          <Cari_Kod>string</Cari_Kod>
          <Puan>string</Puan>
        </bon>
      </_findResult>
    </_findResponse>
  </soap:Body>
</soap:Envelope>

最简单的方法是:

$client = new SoapClient('http://www.webservicex.net/geoipservice.asmx?WSDL');
$result = $client->GetGeoIP(array('IPAddress' => '8.8.8.8'));
print_r($result);

这会给你:

stdClass Object
(
    [GetGeoIPResult] => stdClass Object
        (
            [ReturnCode] => 1
            [IP] => 8.8.8.8
            [ReturnCodeDetails] => Success
            [CountryName] => United States
            [CountryCode] => USA
        )
)

现在,您可以简单地通过调用来访问值

$country = $result->GetGeoIPResult->CountryName;

已在此处回答

php.net soap类