Skip to content

Instantly share code, notes, and snippets.

@Lvcios
Created January 2, 2021 22:04
Show Gist options
  • Select an option

  • Save Lvcios/145dd5848ba3693ea805004d97d7e2b1 to your computer and use it in GitHub Desktop.

Select an option

Save Lvcios/145dd5848ba3693ea805004d97d7e2b1 to your computer and use it in GitHub Desktop.
<?php
$location = "http://localhost/soap-php/index.php?wsdl";
$request = "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mis=\"miSuperSoap2020.alv\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">
<soapenv:Header/>
<soapenv:Body>
<mis:guardarOrdenDeCompra soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
<name xsi:type=\"mis:ordenDeCompra\">
<!--You may enter the following 5 items in any order-->
<NumeroOrden xsi:type=\"xsd:string\">1000</NumeroOrden>
<Ordenante xsi:type=\"xsd:string\">Lucio</Ordenante>
<Moneda xsi:type=\"xsd:string\">MXN</Moneda>
<TipoCambio xsi:type=\"xsd:decimal\">1</TipoCambio>
<Articulos xsi:type=\"mis:listaArticulos\" soapenc:arrayType=\"mis:articulo[]\"/>
</name>
</mis:guardarOrdenDeCompra>
</soapenv:Body>
</soapenv:Envelope>";
print("Request: <br>");
print("<pre>".htmlentities($request)."</pre>");
$action = "guardarOrdenDeCompra";
$headers = [
'Method: POST',
'Connection: Keep-Alive',
'User-Agent: PHP-SOAP-CURL',
'Content-Type: text/xml; charset=utf-8',
'SOAPAction: "guardarOrdenDeCompra"',
];
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
//tipo de autorización
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);//NTLM para webservices con dominios de windows
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);//AUTH BASIC para este caso
curl_setopt($ch, CURLOPT_USERPWD, 'lucio:lucio'); //usuario:contraseña
$response = curl_exec($ch);
$err_status = curl_error($ch);
print("Response: <br>");
print("<pre>".$response."</pre>");
@henrypandales
Copy link
Copy Markdown

Favor recuerdame donde puedo descargar el index.php
gracias, excelente trabajo

@Lvcios
Copy link
Copy Markdown
Author

Lvcios commented Nov 22, 2021

@henrypandales este el index.php: https://gist.github.com/Lvcios/d32bd6823193144070c06b7f77149991
Y la playlist donde lo explico: https://www.youtube.com/watch?v=Rt72TGtACLw&list=PLQBjcJrfqoGq70Oi8rwkmT26lQvyg8s7E

Si tienes comentarios para mejorar el código por favor haz un pull request, agradecería enormente tener un poco de retroalimentación.

Un saludo y gusto en ayudarte.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment