PHP 以POST方式提交XML、獲取XML,最后解析XML


以POST方式提交XML

// Do a POST
$data="<?xml version='1.0' encoding='UTF-8'?>
<TypeRsp>
<CONNECT_ID>1</CONNECT_ID>
<MO_MESSAGE_ID>2</MO_MESSAGE_ID>
</TypeRsp>";

//$data = array('name' => 'Dennis', 'surname' => 'Pallett');

// create a new curl resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL,"http://localhost/handle_form.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// grab URL, and print
curl_exec($ch);

獲取POST來到XML,並解析
handle_form.php

$file_in = file_get_contents("php://input"); //接收post數據

$xml = simplexml_load_string($file_in);//轉換post數據為simplexml對象

foreach($xml->children() as $child)    //遍歷所有節點數據
{

echo $child->getName() . ": " . $child . "<br />"; //打印節點名稱和節點值

//if($child->getName()=="from")    //撿取要操作的節點
//{
//echo "i say ". ": get you!" . "<br />"; //操作節點數據
//}
}

exit;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM