一.问答题

1.curl_setopt中超时设置,URL设置,post数据接收设置,解压缩设置,HEADER信息设置的参数名分别是什么?

2.curl批量设置参数的函数是什么?

二.编程题

1.封装一个curl类,提供get,post方法,通过传递url,data数据获取某个网址的内容,方法返回信息格式为array('response'=>'网页内容','status'=>'http请求状态码','error'=>'错误信息')

要求能够改header信息,并且有超时机制,zip解压缩功能


一.问答题

1.CURLOPT_TIMEOUT,CURLOPT_URL,CURLOPT_POSTFILEDS,CURLOPT_ENCODING,CURLOPT_HTTPHEADER

2.curl_setopt_array($ch,$options);

二.编程题

1.

<?php
class curl{ private $ch = '';
private $timeout = 5;
public $options = array();
public $headers = array();
public $url = ''; function __construct()
{
$this -> ch = curl_init();
$this -> headers[] = "Accept: */*";
$this -> headers[] = "Accept-Encoding: gzip,deflate,sdch";
$this -> headers[] = "Connection: keep-alive";
} public function get($url,$timeout = NULL)
{
$this -> url = $url;
$this -> options[CURLOPT_TIMEOUT] = $timeout?$timeout : $this -> timeout;
$this -> setopt();
return $this -> result();
} public function post($url,$data,$timeout = NULL)
{
$this -> url = $url;
$this -> options[CURLOPT_TIMEOUT] = $timeout?$timeout : $this -> timeout;
$this -> options[CURLOPT_POST] = true;
$this -> options[CURLOPT_POSTFIELDS] = $data;
$this -> setopt();
return $this -> result();
} private function setopt()
{
curl_setopt($this -> ch, CURLOPT_URL, $this -> url);
curl_setopt($this -> ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this -> ch, CURLOPT_ENCODING , 'gzip');
curl_setopt($this -> ch, CURLOPT_HTTPHEADER, $this -> headers);
curl_setopt_array($this -> ch, $this -> options);
} private function execs() {return curl_exec($this -> ch);}
private function status(){return curl_getinfo($this -> ch, CURLINFO_HTTP_CODE);}
private function error() {return (curl_errno($this -> ch))?curl_error($this -> ch) : '';}
private function result()
{
$result['response'] = $this -> execs();
$result['status'] = $this -> status();
$result['error'] = $this -> error();
return $result;
}
}

PHP之curl函数相关试题的更多相关文章

  1. 大公司的PHP面试题

    1. 禁用COOKIE 后 SEESION 还能用吗? 2. 抓取远程图片到本地,你会用什么函数? 4. 你觉得在pV10W的时候, 同等配置下,LUNIX 比WIN快多少? 5. 简述pOST 和G ...

  2. php面试题及答案收藏(转)

    php面试题及答案收藏(这套试题是在网上看到的,不知作者是谁) 基础题 1.表单中 get与post提交方法的区别? 答:get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据, ...

  3. PHP极客水平测试——给创业公司用的远程面试题

    出了份面试题<PHP极客水平测试>,创业公司可以用这个远程笔试啦,先答题,看答案合适了再邀请面试.希望对创业公司有所帮助,欢迎围观提建议哦^_^ 题目会持续更新. 答题地址:http:// ...

  4. php面试题之一——PHP核心技术(高级部分)

    一.PHP核心技术 1.写出一个能创建多级目录的PHP函数(新浪网技术部) <?php /** * 创建多级目录 * @param $path string 要创建的目录 * @param $m ...

  5. php面试题之三——PHP网络编程(高级部分)

    三.PHP网络编程 [!!!]1.禁用COOKIE后SEESION还能用吗?(51.com笔试题) 可以,COOKIE和SESSION都是用来实现会话机制的,由于http协议是无状态的,所以要想跟踪一 ...

  6. Shell企业案例实战和企业面试题

    shell企业面试题 1.批量创建带有随机小写字符文件程序 使用for循环在/pizza目录下创建10个html文件,其中每个文件包含10个随机小写字母加固定字母_pizza 1.思路分析: 核心是: ...

  7. PHP 高级工程面试题汇总

    PHP高级工程面试题汇总(2018.05) 1.给你四个坐标点,判断它们能不能组成一个矩形,如判断([0,0],[0,1],[1,1],[1,0])能组成一个矩形. 勾股定理,矩形是对角线相等的四边形 ...

  8. Linux rhcsa认证考试试题模拟

    声明: 此套试题是2017年rhcsa考试题库,本题库需配合相对应的机器操作,实验环境在我的网盘下载 考试环境: server.group8.example.com 172.24.8.254/24 s ...

  9. linux运维工程师面试题收集

    面试必考 mysql5和mysql6 有什么区别 mysql-server-5.5:默认引擎改为Innodb,提高了性能和扩展性,提高实用性(中继日志自动恢复) mysql-server-5.6:In ...

随机推荐

  1. 网络最大流最短增广路Dinic算法模板

    #include<cstdio> #include<cstring> #include<string> #include<cmath> #include ...

  2. hdu 3631 Shortest Path

    floyd算法好像很奇妙的样子.可以做到每次加入一个点再以这个点为中间点去更新最短路,效率是n*n. #include<cstdio> #include<cstring> #i ...

  3. memcached and redis

    http://hzp.iteye.com/blog/1872664 http://www.diggerplus.org/archives/190 Redis

  4. js--事件对象的理解1

    在触发DOM上的某个事件时,会产生一个事件对象event.这个对象中包含着所有与事件有关的信息.包括导致事件的元素,事件的类型以及其他与特定事件相关的信息. 举例鼠标操作导致的事件对象中,会包含鼠标位 ...

  5. webpack-hot-middleware 用于 livereload

    https://github.com/glenjamin/webpack-hot-middleware Webpack hot reloading using only webpack-dev-mid ...

  6. 三、WCF的宿主

    注:本文为学习摘抄,原文地址:http://www.cnblogs.com/iamlilinfeng/archive/2012/10/01/2706353.html 一.WCF服务应用程序与WCF服务 ...

  7. 带密钥的sha1加密

    带密钥的sha1加密: private static string HmacSha1Sign(string jsonStr, string secretKey, string enCoding ) { ...

  8. 记2016商大ACM省赛

    比赛前三天才得到省赛的非正式参赛名额,总有点哭笑不得,笑的是是我的终究是我的,跑不掉…… 哭的是现在就剩三天了,虽然最近也一直在参加训练赛,但一直是断断续续的,对自己现在的水平并没有太大的信心…… 虽 ...

  9. Swift-HELP

    //获取网页地址对应的字符串 var urlString = url.absoluteURL.absoluteString

  10. VMWare网络链接三种方式

    本文转自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/03/15/1985084.html VMware虚拟机上网络连接(networ ...