首页 > Web开发 > 详细

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

时间:2015-03-25 11:41:38      阅读:276      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.cnblogs.com/jiaxu/p/4364974.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!