• http_post_data发送数据的获取方式


    private function http_get_data($url){
            $ch = curl_init($url) ;
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回
            curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回
            $data = curl_exec($ch) ;
            if (curl_errno($ch)) {
                $this->ErrorLogger('curl get falied. Error Info: '.curl_error($ch));
                return $ch;
            }
            curl_close($ch) ;
            return $data;
        }
    
        public function http_post_data($url, $data_string) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    'Content-Type: application/json; charset=utf-8',
                    'Content-Length: ' . strlen($data_string))
            );
            ob_start();
            $ret = curl_exec($ch);
            if (curl_errno($ch)) {
               // $this->ErrorLogger('curl post falied. Error Info: '.curl_error($ch));
            }
            $return_content = ob_get_contents();
            ob_end_clean();
            return $return_content;
    
        }

    发送数据:

    $arr=array('filed'=>'*','where'=>array('accountun'=>$uname,'accountpwd'=>$upwd) );
    $rs = $this->http_post_data($url,json_encode($arr));

    获取数据:

    $this->arrdata = json_decode($GLOBALS['HTTP_RAW_POST_DATA'],true);
  • 相关阅读:
    Apache部署Django项目
    Docker
    常用算法
    Go之基本数据类型
    Go之流程控制
    Go基本使用
    Go安装与Goland破解永久版
    Linux
    详解java中的byte类型
    Linux统计文本中某个字符串出现的次数
  • 原文地址:https://www.cnblogs.com/finnlee/p/5175622.html
Copyright © 2020-2023  润新知