无法通过PHP使用SOAP API连接到站点

时间:2019-09-10 07:10:35

标签: php curl soap

以下是示例SOAP请求

在这里,我正在发送请求以获取hello world字符串,但它给出了错误。我在下面附上了我的代码和肥皂请求。

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);
  }

?>

运行此代码后,出现类似错误

Curl error: Failed to connect to bocini.com.au port 9081: Connection refused

请为我的问题提供解决方案?

0 个答案:

没有答案