Home » Php » Consuming Web Service using Curl PHP

Consuming Web Service using Curl PHP

Posted by: admin February 23, 2020 Leave a comment

Questions:

I have a problem using SoapClient, I was looking for info and may be is a bug with PHP(7.3) and a problem with the Web Service, because PHP shows the following error:

[05-Feb-2020 22:05:15 America/Bogota] PHP Fatal error: SOAP-ERROR: Parsing Schema: element ‘http://xxx.xxx.xxx‘ already defined in C:\wamp64\www\proyect\fac_electronic.php on line 364.

Now I am trying the following code using curl, but I don’t see where is the error.

<?php
set_time_limit(0);
$factura = base64_encode(file_get_contents('FA_2.txt'));

$envelope='<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <EmisionDocElecArchivoSustentoRqt xmlns="http://xxx.xxx.xxx">
            <cuenta xmlns="">FAC0</cuenta>
            <empresa xmlns="">FAC</empresa>
            <usuario xmlns="">USR_FAC001</usuario>
            <Documento xmlns="">'.$factura.'</Documento>
            <tipoDocumento xmlns="">F</tipoDocumento>
            <!-- Optional -->
            <documentosSustento xmlns="">
                <docSustento>'.$factura.'</docSustento>
                <extensionDocSustento>txt</extensionDocSustento>
            </documentosSustento>
        </EmisionDocElecArchivoSustentoRqt>
    </Body>
</Envelope>';

$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL,"http://xxx.xxx.xxx:8150/wsdl?configName=ProcesarFactura");
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,$envelope); 
curl_setopt($soap_do, CURLOPT_VERBOSE,TRUE); 
curl_setopt($soap_do, CURLOPT_HTTPHEADER,array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($envelope)));

$result = curl_exec($soap_do);
if (curl_errno($soap_do)) {
                    echo '...Request Error:' . curl_error($soap_do);
                }

var_dump($result);
How to&Answers: