2

Estoy tratando de hacer un post utilizando la libreria soap con php pero cada vez que estoy ejecutando la consulta me lanza tipo de medio no permitido creo que el post debe ser del tipo json ¿Cómo puedo solucionarlo alguien me ayuda por favor?

<?php 
 //Data, connection, auth
 //$dataFromTheForm = $_POST['fieldName']; // request data from the form
//En esta parte es donde debería abrir la conección 
 $soapUrl = "http://192.168.26.16:8080/Licencias/rest/wsbepsamov?op=DoSomething"; // asmx URL of WSDL
 $user = "test";  //  username
 $password = "123456"; // password
 $documento = "34115410";
 $tarjeta = "6274311750000090";
 // xml post structure

 $xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
                     <soap:Envelope xmlns:xsi="http://192.168.26.16:8080/Licencias/rest/wsbepsamov" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                       <soap:Body>
                         <GetItemPrice xmlns="http://192.168.26.16:8080/Licencias/rest/wsbepsamov"> // xmlns value to be set to your WSDL URL
                           <PRICE>'.$dataFromTheForm.'</PRICE> 
                         </GetItemPrice >
                       </soap:Body>
                     </soap:Envelope>';   // data from the form, e.g. some ID number

    $headers = array(
                 "Content-type: text/xml;charset=\"utf-8\"",
                 "Accept: text/xml",
                 "Cache-Control: no-cache",
                 "Pragma: no-cache",
                 "SOAPAction: http://192.168.26.16:8080/Licencias/rest/wsbepsamov", 
                 "Content-length: ".strlen($xml_post_string),
             ); //SOAPAction: your op URL

     $url = $soapUrl;

     // PHP cURL  for https connection with auth
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_USERPWD, $user.":".$password .":".$documento.":".$tarjeta ); // username and password - declared at the top of the doc
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

     // converting
     $response = curl_exec($ch); 
     curl_close($ch);

     // converting
     $response1 = str_replace("<soap:Body>","",$response);
     $response2 = str_replace("</soap:Body>","",$response1);

     // convertingc to XML
     $parser = simplexml_load_string($response2);
     // user $parser to get your data out of XML response and to display it. 
 ?>

1
  • 1
    De hecho, no usas la librería Soap, con cURL es mas trabajo.
    – Sal
    el 17 sep. 2021 a las 0:39

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.