получение данных с сервера в формате xml

0

Я пытаюсь вызвать веб-сервис через php. Я отправляю XML-запрос, для которого я должен вернуть ответ Xml. Но я как ответ получаю только данные без тэгов xml. Я хочу, чтобы он был в правильном формате XML. У меня также есть wsdl файл веб-сайта. Если кто-нибудь может посоветовать, что делать, это будет реальной помощью. Спасибо заранее за ваше время.

<?php  
$soapUrl=some url';
$xml_post_string='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sec="http://schemas.xmlsoap.org/ws/2002/04/secext" xmlns:urn="urn:ebx-schemas:dataservices_1.0">
   <soapenv:Header>
      <sec:Security>
         <UsernameToken>
            <Username>Some Value</Username>
            <Password>Some Value</Password>
         </UsernameToken>
      </sec:Security>
   </soapenv:Header>
   <soapenv:Body>
      <urn:select_ProductDetail>
         <branch>Product</branch>
         <instance>Product</instance>
         <viewPublication>List Name</viewPublication>
      </urn:select_ProductDetail>
   </soapenv:Body>
</soapenv:Envelope>';




   $headers = array( 
   "Content-Type: text/xml;charset=UTF-8", 
   "Accept: gzip,deflate", 
   "Cache-Control: no-cache", 
   "Pragma: no-cache", 
   "SOAPAction: \"select\"", 
    "Host: Host name",
    "Connection: Keep-Alive",       
   "Content-length: ".strlen($xml_post_string), 
   ); 

   // PHP cURL  for https connection with auth
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_URL, $soapUrl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
   curl_setopt($ch, CURLOPT_TIMEOUT, 500);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
   curl_setopt($ch, CURLOPT_MAXREDIRS, 12);
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   $ss = curl_getinfo($ch);
   $response = curl_exec($ch); 
   print_r($response);
   exit;
   curl_close($ch);   
   ?>
Теги:

2 ответа

0
Лучший ответ

Попробуйте изменить свои коды ниже, для просмотра в браузерах

   $ss = curl_getinfo($ch);
   $response = curl_exec($ch); 
   echo '<pre>';
   echo htmlspecialchars(print_r($response, true));
   echo '</pre>';
   #print_r($response);
   exit;
   curl_close($ch);
  • 0
    Большое спасибо: D Теперь это работает. Огромное спасибо еще раз
0

Вы не получаете вывод в формате xml, потому что вывод конкатенируется с заголовком curl, чтобы избежать использования ниже кода

//PHP cURL для соединения https с auth

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_URL, $soapUrl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
   curl_setopt($ch, CURLOPT_TIMEOUT, 500);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
   curl_setopt($ch, CURLOPT_MAXREDIRS, 12);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   $ss = curl_getinfo($ch);
   //$response will give you xml format code
   $response = curl_exec($ch); 
   //$xml will create array from that xml format code
   $xml=simplexml_load_string($response);
   print_r($xml);
   exit;
   curl_close($ch);  

Ещё вопросы

Сообщество Overcoder
Наверх
Меню