用PHP调用SOAP方法和curl函数


Calling a SOAP method with PHP with curl functions

我想尝试在PHP中使用curl函数调用soap方法,但它显示一个警告

警告:curl_setopt() [function。curl-setopt]:第26行/home/bestbus/public_html/apitest.php中的curl配置选项无效

<? 
$xml_data ='<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:rsr="http://webservices.foxfireindia.com/RSRSAPI">
   <soap:Header>
  <rsr:LinkCredentials>
     <!--Optional:-->
     <rsr:Login>***main</rsr:Login>
     <!--Optional:-->
     <rsr:Password>****@3api</rsr:Password>
  </rsr:LinkCredentials>
 </soap:Header>
  <soap:Body>
  <rsr:Login>
       <!--Optional:-->
       <rsr:userName>***main</rsr:userName>
     <!--Optional:-->
     <rsr:password>****@3api</rsr:password>
  </rsr:Login>
  </soap:Body>
 </soap:Envelope>';
$URL = "http://115.254.89.1:8090/RSRS_APITest/RSRSAPI.asmx?wsdl";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
print_r($output);
curl_close($ch);
?>

根据手册,CURLOPT_SSL_VERIFYHOST的唯一有效值是1或2,并且在cURL 7.28.1

中已经删除了1的使用
  • 1检查SSL对端证书中是否存在通用名称。
  • 2检查公共名称的存在,并验证它是否与所提供的主机名匹配。在生产环境中,该选项的值应该保持为2(默认值)。

试试这个:

<?php
    $xml_data = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:rsr="http://webservices.foxfireindia.com/RSRSAPI">
   <soap:Header>
  <rsr:LinkCredentials>
     <!--Optional:-->
     <rsr:Login>***main</rsr:Login>
     <!--Optional:-->
     <rsr:Password>****@3api</rsr:Password>
  </rsr:LinkCredentials>
 </soap:Header>
  <soap:Body>
  <rsr:Login>
       <!--Optional:-->
       <rsr:userName>***main</rsr:userName>
     <!--Optional:-->
     <rsr:password>****@3api</rsr:password>
  </rsr:Login>
  </soap:Body>
 </soap:Envelope>';
    $URL = "http://115.254.89.1:8090/RSRS_APITest/RSRSAPI.asmx?wsdl";
    $header = array(
                    "Content-type: text/xml;charset='"utf-8'"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "SOAPAction: '"run'"",
                    "Content-length: ".strlen($tresc),
                    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,            $URL);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT,        10);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_POST,           true );
    curl_setopt($ch, CURLOPT_POSTFIELDS,     $xml_data);
    curl_setopt($ch, CURLOPT_HTTPHEADER,     $header);
    $output = curl_exec($ch);
    print_r($output);
    curl_close($ch);
?>

尝试替换

 curl_setopt($ch, CURLOPT_MUTE, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

因为作为文档http://php.net/manual/en/function.curl-setopt.php CURLOPT_MUTE在cURL 7.15.5中被删除