How to post SOAP Request from PHP

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

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

7条回答
  •  粉色の甜心
    2020-12-01 03:50

    If the XML have identities with same name in different levels there is a solution. You don´t have to ever submit a raw XML (this PHP SOAP object don´t allows send a RAW XML), so you have to always translate your XML to a array, like the example below:

    $originalXML = "
    
      
          someone
          R. 1001
      
      
          another one
          
      
    "
    
    //Translate the XML above in a array, like PHP SOAP function requires
    $myParams = array('firstClient' => array('name' => 'someone',
                                      'adress' => 'R. 1001'),
                'secondClient' => array('name' => 'another one',
                                      'adress' => ''));
    
    $webService = new SoapClient($someURL);
    $result = $webService->someWebServiceFunction($myParams);
    

    or

    $soapUrl = "http://privpakservices.schenker.nu/package/package_1.3/packageservices.asmx?op=SearchCollectionPoint";
    
    $xml_post_string = 'XXXXXXXXX-XXXXXX0
    RiksvŠgen 5
    59018Mantorp10
    '; $headers = array( "POST /package/package_1.3/packageservices.asmx HTTP/1.1", "Host: privpakservices.schenker.nu", "Content-Type: application/soap+xml; charset=utf-8", "Content-Length: ".strlen($xml_post_string) ); $url = $soapUrl; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); $response1 = str_replace("","",$response); $response2 = str_replace("","",$response1); $parser = simplexml_load_string($response2);

提交回复
热议问题