zoukankan      html  css  js  c++  java
  • PHP以xml形式获取POST数据

    <?php
    namespace HomeController;
    
    use ThinkController;
    
    class UrlController extends Controller
    {
        //xml形式获取post的值curl
        public function send()
        {
            $header[] = 'Content-type: text/xml';//定义content-type为xml
            $xml = '<xml>';
            $xml .= '<name>name</name>';
            $xml .= '<age>14</age>';
            $xml .= '</xml>';
    
            $url = 'http://localhost/tp/index.php/Home/Url/get';
            $ch = curl_init(); //初始化curl
            curl_setopt($ch, CURLOPT_URL, $url);//设置链接
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//设置是否返回信息
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//设置HTTP头
            curl_setopt($ch, CURLOPT_POST, 1);//设置为POST方式
            curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);//POST数据
            $response = curl_exec($ch);//接收返回信息
            if (curl_errno($ch)) {//出错则显示错误信息
                print curl_error($ch);
            }
            curl_close($ch); //关闭curl链接
            //$response可以显示到
            echo $response;//显示返回信息,
        }
    
        public function get()
        {
            /*$xmldata = file_get_contents("php://input");
            echo $xmldata;*/
    
            if($GLOBALS['HTTP_RAW_POST_DATA'])
            echo $GLOBALS['HTTP_RAW_POST_DATA'];
    }
    }
    $input = $GLOBALS['HTTP_RAW_POST_DATA'];
        libxml_disable_entity_loader(true);
        $xml = simplexml_load_string($input,'SimpleXMLElement',LIBXML_NOCDATA);
        var_dump($xml);
  • 相关阅读:
    斐波那契数列变形
    poj 1061 青蛙的约会+拓展欧几里得+题解
    Leading and Trailing LightOJ
    HDU-1576 A/B 基础数论+解题报告
    swal() 弹出层的用法
    jqurey.running.min.js运动的字体效果
    echarts中dataZoom的使用
    echarts动态添加数据
    设备适配尺寸
    sublime Text3 插件
  • 原文地址:https://www.cnblogs.com/Duriyya/p/6022230.html
Copyright © 2011-2022 走看看