PHP 以POST方式提交XML、获取XML,最后解析XML
(2012-03-09 11:04:24)// Do a POST
$data="<?xmlversion='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 curlresource
$ch =curl_init();
// set URL and otherappropriate 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, andprint
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;