一.问答题

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

最新文章

  1. CrashMonkey4IOS App测试
  2. 在Springmvc中获取properties属性
  3. ubuntu输入su命令显示 Authentication failure解决
  4. 分布式服务框架 Zookeeper(转)
  5. Windows中检测当前是否有窗口全屏
  6. 【原】Storm环境搭建
  7. 史上最强NDK入门项目实战
  8. Cortex-M0系统滴答定时器Systick详解
  9. Oracle中中文、数字,英文混杂形式的字段进行排序的方法
  10. How to change a product dropdown attribute to a multiselect in Magento
  11. Matlab实现PCA
  12. 三、MapReduce学习
  13. Java基础知识整理(一)
  14. 使用scrapy爬虫,爬取17k小说网的案例-方法一
  15. matplotlib基本用法-【老鱼学matplotlib】
  16. vue_drf之支付宝接口
  17. spring创建bean模式singleton与prototype的区别
  18. [转]Redis内部数据结构详解-sds
  19. 如何将Revit明细表导出为Excel文档
  20. MyBatis数据库连接的基本使用-补充

热门文章

  1. 难以记住的sql语句
  2. C#.NET的微信功能开发学习
  3. UVa 1600 Patrol Robot (习题 6-5)
  4. Java中泛型 类型擦除
  5. Token验证失败的解决方法
  6. POJ 3710 Christmas Game#经典图SG博弈
  7. Qt_DX
  8. html5 读写sqlite数据库
  9. Openjudge-计算概论(A)-鸡兔同笼
  10. python读取bin文件并下发串口