普通的curl访问并获取输出内容

<?php

function login_post($url, $encoding = null, $timeout = 10000, $httpActionType = 'Get', $postParameter = "") {
  $encoding == null ? 'gb2312' : $encoding;

        if ($httpActionType == 'Get') {
            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate'));
            curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
            curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout / 1000);
            $html = curl_exec($curl);
            curl_close($curl);
//            return iconv($encoding, 'utf-8', $html);
            return $html;
        } else {
            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $postParameter);
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate'));
            curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
            curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout / 1000);
            $html = curl_exec($curl);
            curl_close($curl);
            return $html;
//            return iconv($encoding, 'utf-8', $html);
        }

posted @ 2015-03-25 10:42  黑面骑士  阅读(3472)  评论(0)    收藏  举报