zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    CS224d lecture 16札记
    CS224d lecture 15札记
    CS224d lecture 14札记
    CS224d lecture 13札记
    将博客搬至CSDN
    三张图理解JavaScript原型链
    三道题理解软件流水
    网络安全密码学课程笔记
    “wuliao“(无聊)聊天软件
    大二小学期C#资产管理大作业小记
  • 原文地址:https://www.cnblogs.com/finnlee/p/5175622.html
Copyright © 2011-2022 走看看