简体   繁体   English

使用CURL调用SOAP WSDL Web服务

[英]Calling SOAP WSDL Webservice using CURL

I'm trying to call a SOAP webservice using CURL and it is not working. 我正在尝试使用CURL调用SOAP Web服务,但它不起作用。 This is the code I have used to invoke webservice using soap client 这是我使用soap客户端调用webservice的代码

 (object)$ProgramClient = new SoapClient('https://mywebserviceurl?wsdl',array(
'login' => "username", 'password' => "password",
'location' => 'https://someotherurl'
));

(object)$objResult1 = $ProgramClient->GetEvents(array (
'EventsRequest' => array (
'Source' => array (
'SourceId' => 'SOURCEID', 'SystemId' => 'SYTEMID')
 )));

 $event_info = $objResult1->EventsResponse;

This is working fine and I converted this call using CURL and it stopped working. 一切正常,我使用CURL转换了此调用,但它停止了工作。 Here is my code using CURL 这是我使用CURL的代码

      $credentials = "username:password"; 
      $url = "https://mywebserviceurl?wsdl";
      $body = '<?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>
                            <GetEvents xmlns="https://umywebserviceurl?wsdl"> 
                             </GetEvents >
                          </soap:Body>
                        </soap:Envelope>'; 
        $headers = array( 
'Content-Type: text/xml; charset="utf-8"', 
'Content-Length: '.strlen($body), 
'Accept: text/xml', 
'Cache-Control: no-cache', 
'Pragma: no-cache', 
'SOAPAction: "GetEvents"'
); 

  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_URL, $url); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
  curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

  // Stuff I have added
 curl_setopt($ch, CURLOPT_POST, true); 
 curl_setopt($ch, CURLOPT_POSTFIELDS, $body); 
 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
 curl_setopt($ch, CURLOPT_USERPWD, $credentials);

  $data = curl_exec($ch);


  echo '<pre>';
  print_r($data);

Could anyone tell me what I'm missing here.. 谁能告诉我我在这里想念的..

Regards Jayesh 问候杰伊什

Its basic example what you need and used to call SOAP webservice using CURL You will also used extra parameters which you are used in your web service call. 它的基本示例是您所需要的,并用于使用CURL调用SOAP Web服务。您还将使用在Web服务调用中使用的额外参数。

$soapDo = curl_init();

curl_setopt($soapDo, CURLOPT_URL, "[productionURL]"); // Used "[testingURL]" in testing

curl_setopt($soapDo, CURLOPT_USERPWD, "[username]:[password]");

curl_setopt($soapDo, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

curl_setopt($soapDo, CURLOPT_CONNECTTIMEOUT, 10);

curl_setopt($soapDo, CURLOPT_TIMEOUT, 10);

curl_setopt($soapDo, CURLOPT_RETURNTRANSFER, true);

curl_setopt($soapDo, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($soapDo, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($soapDo, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($soapDo, CURLOPT_POST, true );

curl_setopt($soapDo, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); // The system running this script must have TLS v1.2 enabled, otherwise this will fail

curl_setopt($soapDo, CURLOPT_POSTFIELDS, $xml); // This has to be an XML  string matching the Advantex XML requirements from the WSDL.

curl_setopt($soapDo, CURLOPT_HTTPHEADER, array("Content-Type: text/xml; charset=utf-8", "Content-Length: " . strlen($xml)));

$result = curl_exec($soapDo);

$err = curl_error($soapDo);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM