sendXML.php <!--发送XML的页面-->
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?php $xml_data = '<xml>...</xml>'; $url = 'http://localhost/getXML.php'; $header = "Content-type: text/xml"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data); $response = curl_exec($ch); if(curl_errno($ch)){ print curl_error($ch); } curl_close($ch); echo $response; ?>
|
getXML.php <!--接收XML的页面-->
1 2 3 4 5 6 7 8 9 10 11 12
| <?php $xml = file_get_contents('php://input'); if($xml!=''){ $fp = fopen('xml.txt','w'); fwrite($fp,$xml); fclose($fp); exit('OK'); } die('Fail'); ?>
|