Thursday, December 12, 2013

php: send xml in post request and read xml in post request

to send xml data in post request using curl:
<?php
        $XMLreq = '<?xml version="1.0" encoding="UTF-8"?>';
        $XMLreq = $XMLreq . '<!DOCTYPE svc_init SYSTEM "http://x.x.x.x/sample.DTD">';
        $XMLreq = $XMLreq . '<svc_init ver="1.0.0">';
        $XMLreq = $XMLreq . '<object>sample</object>';
        $XMLreq = $XMLreq . '</svc_init>';
        $URLreq = "http://x.x.x.x/XMLreceive.php";

        $ch = curl_init($URLreq);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $XMLreq);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 45);
        $output = curl_exec($ch);
        curl_close($ch);
        echo $output;
?>

to read xml data received in post request:
<?php
        if(isset($HTTP_RAW_POST_DATA))
        {
                echo $HTTP_RAW_POST_DATA;
        }
?>

No comments:

Post a Comment

SSH : No matching host key type found. Their offer: ssh-rsa,ssh-dss

Got this while connecting to my mikrotik router via ssh   Unable to negotiate with <ip address> port <ssh port>: no matching hos...