XML : Send xml and fetch xml from server in php

There are lot of question on web and stackoverflow about this topic. but still I am not able to sort out my problem.

Here is the code of sending and receiving the data. But I am only able to get header data. I want body data too. What I need to change here.

  <?php  $xml = file_get_contents('check.xml');  $url = 'https://interface.demo.gta-travel.com/wbsapi/RequestListenerServlet';     //setting the curl parameters.   $headers = array(      "Content-type: text/xml;charset=\"utf-8\"",      "Accept: text/xml",      "Cache-Control: no-cache",      "Pragma: no-cache",      "SOAPAction: \"run\""   );          try{              $ch = curl_init();              curl_setopt($ch, CURLOPT_URL, $url);              curl_setopt($ch, CURLOPT_POST, 1);              // send xml request to a server              curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);              curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);              curl_setopt($ch, CURLOPT_POSTFIELDS,  $xml);              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);              curl_setopt($ch, CURLOPT_VERBOSE, 0);              curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);              $data = curl_exec($ch);                  //convert the XML result into array              if($data === false){                  $error = curl_error($ch);                  echo $error;                   die('error occured');              }else{                  echo '<pre>';                  echo htmlspecialchars(print_r($data, true));                  echo '</pre>';                            }              curl_close($ch);          }catch(Exception  $e){              echo 'Message: ' .$e->getMessage();die("Error");      }  ?>    

No comments:

Post a Comment