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);

 

你可能感兴趣的:(http_post_data发送数据的获取方式)