<?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);
        }
原文:http://www.cnblogs.com/jiaxu/p/4364974.html