base:examples
Sample code for communication with the service
- request_example.php
<?php
function post_xml($url, $xml){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$xml = new XMLWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('mds');
$xml->startElement('auth');
$xml->writeElement('login', 'login');
$xml->writeElement('pass', 'hasło');
$xml->endElement();
$xml->startElement('request');
$xml->writeElement('type', 'offers');
$xml->startElement('conditions');
$xml->writeElement('par_adt', 2);
$xml->endElement();
$xml->endElement();
$xml->endElement();
$xml->endDocument();
$xml_response_string = post_xml('http://mws.merlinx.pl/dataV4/', $xml->outputMemory(true));
if(!$xml_response_string)
die('ERROR');
$xml_response = simplexml_load_string($xml_response_string);
?>
base/examples.txt · Last modified: 2017/06/08 11:58 by marekj