当我尝试通过SOAP API和PHP

时间:2019-09-17 04:22:54

标签: php rest api soap

我尝试发送请求以获取Hello World字符串,但出现错误,我不知道为什么。我将附加我的代码,并放置我的错误代码。请帮助我解决此SOAP API问题。

这是我在运行代码时收到的错误消息

  

卷曲错误:无法连接到bocini.com.au端口9081:连接被拒绝

这是API代码

POST /3rdpartyedi/infosvr.asmx HTTP/1.1
Host: bocini.com.au
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/HelloWorld"

<?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>
    <HelloWorld xmlns="http://tempuri.org/" />
  </soap:Body>
</soap:Envelope>

这是我的PHP代码

$soap_request = '<?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>
      <HelloWorld xmlns="http://tempuri.org/" />
    </soap:Body>
  </soap:Envelope>';


$header = array(
  'Content-type: text/xml;charset=utf-8',
  'Accept: text/xml',
  'SOAPAction: http://tempuri.org/ListAllStyleClassifications',
    'Content-length: '.strlen($soap_request),
);

$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://bocini.com.au:9081/3rdpartyedi/infosvr.asmx?wsdl" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST,           true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);

$result = curl_exec($soap_do);

if(curl_exec($soap_do) === false) {
  $err = 'Curl error: ' . curl_error($soap_do);
  curl_close($soap_do);
  print $err;
} else {
  curl_close($soap_do);
  print 'success<br>';
  print_r($result);
}

0 个答案:

没有答案