How to post SOAP Request from PHP

后端 未结 7 793
野趣味
野趣味 2020-12-01 03:39

Anyone know how can I post a SOAP Request from PHP?

7条回答
  •  没有蜡笔的小新
    2020-12-01 04:11

    We can use the PHP cURL library to generate simple HTTP POST request. The following example shows you how to create a simple SOAP request using cURL.

    Create the soap-server.php which write the SOAP request into soap-request.xml in web folder.

    We can use the PHP cURL library to generate simple HTTP POST request. The following example shows you how to create a simple SOAP request using cURL.
    
    Create the soap-server.php which write the SOAP request into soap-request.xml in web folder.
    
    
    
    
    
    The next step is creating the soap-client.php which generate the SOAP request using the cURL library and send it to the soap-server.php URL.
    
    \n";
      $soap_request .= "\n";
      $soap_request .= "  \n";
      $soap_request .= "    \n";
      $soap_request .= "      IBM\n";
      $soap_request .= "    \n";
      $soap_request .= "  \n";
      $soap_request .= "";
    
      $header = array(
        "Content-type: text/xml;charset=\"utf-8\"",
        "Accept: text/xml",
        "Cache-Control: no-cache",
        "Pragma: no-cache",
        "SOAPAction: \"run\"",
        "Content-length: ".strlen($soap_request),
      );
    
      $soap_do = curl_init();
      curl_setopt($soap_do, CURLOPT_URL, "http://localhost/php-soap-curl/soap-server.php" );
      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);
    
      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 'Operation completed without any errors';
      }
    ?>
    
    
    Enter the soap-client.php URL in browser to send the SOAP message. If success, Operation completed without any errors will be shown and the soap-request.xml will be created.
    
    
    
      
        
          IBM
        
      
    
    
    
    Original - http://eureka.ykyuen.info/2011/05/05/php-send-a-soap-request-by-curl/
    

提交回复
热议问题