• 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;
  • 相关阅读:
    镜像的上传和下载
    ps 命令
    过滤不合格数据
    云计算5-3-2法则
    Python Django初入门
    python web框架
    BootStrap、EasyUI、JQueryUI
    JS正则
    ngonx FastCGI 相关参数调优
    Windows10远程连接错误-出现身份验证错误
  • 原文地址:https://www.cnblogs.com/baocheng/p/5902972.html
Copyright © 2020-2023  润新知