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;
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!