呆呆鱼

curl方法post一个数组

$r = $this->curl_post($url, $data);
$list = json_decode($r,true);


 
function curl_post($url = '', $post_data = array())
  {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        //以文件流的形式返回,而不直接输出
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // post数据
        curl_setopt($ch, CURLOPT_POST, 1);
        // post的变量
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
        $output = curl_exec($ch);
        curl_close($ch);
        //打印获得的数据
        //return $output;
        return trim(str_replace("\r\n", "", $output));

  }

posted on 2016-12-08 18:01  呆呆鱼  阅读(6433)  评论(0编辑  收藏  举报

导航