PHP之curl函数相关试题
一.问答题
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函数相关试题的更多相关文章
- 大公司的PHP面试题
1. 禁用COOKIE 后 SEESION 还能用吗? 2. 抓取远程图片到本地,你会用什么函数? 4. 你觉得在pV10W的时候, 同等配置下,LUNIX 比WIN快多少? 5. 简述pOST 和G ...
- php面试题及答案收藏(转)
php面试题及答案收藏(这套试题是在网上看到的,不知作者是谁) 基础题 1.表单中 get与post提交方法的区别? 答:get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据, ...
- PHP极客水平测试——给创业公司用的远程面试题
出了份面试题<PHP极客水平测试>,创业公司可以用这个远程笔试啦,先答题,看答案合适了再邀请面试.希望对创业公司有所帮助,欢迎围观提建议哦^_^ 题目会持续更新. 答题地址:http:// ...
- php面试题之一——PHP核心技术(高级部分)
一.PHP核心技术 1.写出一个能创建多级目录的PHP函数(新浪网技术部) <?php /** * 创建多级目录 * @param $path string 要创建的目录 * @param $m ...
- php面试题之三——PHP网络编程(高级部分)
三.PHP网络编程 [!!!]1.禁用COOKIE后SEESION还能用吗?(51.com笔试题) 可以,COOKIE和SESSION都是用来实现会话机制的,由于http协议是无状态的,所以要想跟踪一 ...
- Shell企业案例实战和企业面试题
shell企业面试题 1.批量创建带有随机小写字符文件程序 使用for循环在/pizza目录下创建10个html文件,其中每个文件包含10个随机小写字母加固定字母_pizza 1.思路分析: 核心是: ...
- PHP 高级工程面试题汇总
PHP高级工程面试题汇总(2018.05) 1.给你四个坐标点,判断它们能不能组成一个矩形,如判断([0,0],[0,1],[1,1],[1,0])能组成一个矩形. 勾股定理,矩形是对角线相等的四边形 ...
- Linux rhcsa认证考试试题模拟
声明: 此套试题是2017年rhcsa考试题库,本题库需配合相对应的机器操作,实验环境在我的网盘下载 考试环境: server.group8.example.com 172.24.8.254/24 s ...
- linux运维工程师面试题收集
面试必考 mysql5和mysql6 有什么区别 mysql-server-5.5:默认引擎改为Innodb,提高了性能和扩展性,提高实用性(中继日志自动恢复) mysql-server-5.6:In ...
随机推荐
- ImageView.ScaleType设置图解
图文相配很清晰的看出每个属性的效果, 感觉 CENTER_CROP 比较有用,长宽自动适应 ImageView ,整个图片自动缩略填充整个区域且居中显示(高宽不一定是view的尺寸),以前用JS在网页 ...
- ACdream 1063 平衡树
写的很丑的字典树.听王大神的话 需要改进. #include<stdio.h> #include<string.h> #include<math.h> #incl ...
- NodeJS学习指南
七天学会NodeJS NodeJS基础 什么是NodeJS 有啥用处 如何安装 安装程序 编译安装 如何运行 权限问题 模块 require exports module 模块初始化 主模块 完整示例 ...
- 测试word 2013发布blog
测试图片和各种格式 使用Windows Live Writer 2012和Office Word 2013 发布文章到博客园全面总结 (亲测可用) 我的一些感受: 缺点 (1) Word201 ...
- Storm常见问题处理
错误1:发布topologies到远程集群时,出现Nimbus host is not set异常.异常内容如下所示: [root@xop-dev-a bin]# ./storm jar /home/ ...
- $each $position $sort $slice
$push 向数组中添加元素 $each 循环数据(循环添加数据到数组) $sort 对数组进行排序(1:升序:-1:降序.) $slice 对整个collection表进行数据裁减,用的时候一定要当 ...
- IntelliJ IDEA 13.1.4新建java web项目
打开软件
- SASL - 简单认证和安全层
转自:http://blog.csdn.net/id19870510/article/details/8232509 SASL - 简单认证和安全层 SASL是一种用来扩充C/S模式验证能力的机制认证 ...
- Java多态(二)
public class ExtendsTest { public static void main(String[] args) { A a1 = new A(); A a2 = new B(); ...
- zookeeper的安装及集群配置
1.解压 2.修改配置文件 cp zoo_sample.cfg zoo.cfg vim zoo.cfg dataDir=/usr/local/zookeeperData 其余采用默认 参数说明: ti ...