一、Requests for PHP

官网:http://requests.ryanmccue.info
官方介绍:
Requests is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.
Requests是一个谦虚的HTTP请求类库,它简化你与其他网站的交互并把你的一些烦恼带走。
如何使用:
1、下载:https://github.com/rmccue/Requests/archive/v1.6.0.zip 
2、解压缩,得到如下文件

把library目录重名称为requests,然后拷贝到程序的类库文件夹

3、引用类库文件

require_once ('requests/Requests.php');
4、让程序自动引用相关内部类库(一定要执行这行代码)

Requests::register_autoloader();
5、开始使用GET或POST请求获取远程数据

$response = Requests::get('https://github.com/timeline.json');
var_dump($response);

常用方法说明:
1、使用GET发送请求获取远程数据 Requests::get($url, $headers = array(), $options = array());
这里有3个参数可以使用
第1个参数:$url 为需要获取远程数据的url链接,例如:

$response = Requests::get('https://github.com/timeline.json');
第2个参数:$headers = array() 为附加的头部请求

array('Accept' => 'application/json')

 

第3个参数:$options = array() 为配置参数

`timeout`: 设置响应超时时间
(integer, seconds, default: 10)
`useragent`: 设置发送到服务器的用户代理
(string, default: php-requests/$version)
`follow_redirects`: 是否允许3XX重定向
(boolean, default: true)
`redirects`: How many times should we redirect before erroring?
(integer, default: 10)
`blocking`: Should we block processing on this request?
(boolean, default: true)
`filename`: File to stream the body to instead.
(string|boolean, default: false)
`auth`: Authentication handler or array of user/password details to use for Basic authentication
(Requests_Auth|array|boolean, default: false)
`proxy`: Proxy details to use for proxy by-passing and authentication
(Requests_Proxy|array|boolean, default: false)
`idn`: Enable IDN parsing
(boolean, default: true)
`transport`: Custom transport. Either a class name, or a transport object. Defaults to the first working transport from
{@see getTransport()}
(string|Requests_Transport, default: {@see getTransport()})
`hooks`: Hooks handler.
(Requests_Hooker, default: new Requests_Hooks())
`verify`: Should we verify SSL certificates? Allows passing in a custom
certificate file as a string. (Using true uses the system-wide root
certificate store instead, but this may have different behaviour
across transports.)
(string|boolean, default: library/Requests/Transport/cacert.pem)
`verifyname`: Should we verify the common name in the SSL certificate?
(boolean: default, true)

2、使用POST发送请求获取远程数据 Requests::post($url, $headers = array(), $data = array(), $options = array());
这里有4个参数可以使用,多了一个请求数据(相当于表单提交的数据),其实get也有这个数据,get请求直接附加在url上了

第1个参数:$url 同get的第一个参数
第2个参数:$headers = array() 同get的第2个参数
第4个参数:$options = array() 同get的第3个参数
第3个参数:$data = array() 为表单提交的数据

Http Requests for PHP的更多相关文章

  1. requests的content与text导致lxml的解析问题

    title: requests的content与text导致lxml的解析问题 date: 2015-04-29 22:49:31 categories: 经验 tags: [Python,lxml, ...

  2. requests源码阅读学习笔记

    0:此文并不想拆requests的功能,目的仅仅只是让自己以后写的代码更pythonic.可能会涉及到一部分requests的功能模块,但全看心情. 1.另一种类的初始化方式 class Reques ...

  3. Python爬虫小白入门(二)requests库

    一.前言 为什么要先说Requests库呢,因为这是个功能很强大的网络请求库,可以实现跟浏览器一样发送各种HTTP请求来获取网站的数据.网络上的模块.库.包指的都是同一种东西,所以后文中可能会在不同地 ...

  4. 使用beautifulsoup与requests爬取数据

    1.安装需要的库 bs4 beautifulSoup  requests lxml如果使用mongodb存取数据,安装一下pymongo插件 2.常见问题 1> lxml安装问题 如果遇到lxm ...

  5. python爬虫学习(6) —— 神器 Requests

    Requests 是使用 Apache2 Licensed 许可证的 HTTP 库.用 Python 编写,真正的为人类着想. Python 标准库中的 urllib2 模块提供了你所需要的大多数 H ...

  6. ImportError: No module named 'requests'

    补充说明: 当前环境是在windows环境下 python版本是:python 3.4. 刚开始学习python,一边看书一边论坛里阅读感兴趣的代码, http://www.oschina.net/c ...

  7. Python-第三方库requests详解

    Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...

  8. Requests 乱码

    当使用Requests请求网页时,出现下面图片中的一些乱码,我就一脸蒙逼. 程序是这样的. def getLinks(articleUrl): headers = { "Uset-Agent ...

  9. 爬虫requests模块 2

    会话对象¶ 会话对象让你能够跨请求保持某些参数.它也会在同一个 Session 实例发出的所有请求之间保持 cookie, 期间使用 urllib3 的 connection pooling 功能.所 ...

  10. 爬虫requests模块 1

    让我们从一些简单的示例开始吧. 发送请求¶ 使用 Requests 发送网络请求非常简单. 一开始要导入 Requests 模块: >>> import requests 然后,尝试 ...

随机推荐

  1. linux 查看和修改文件时间

    参考:https://www.cnblogs.com/chjbbs/p/6437879.html?utm_source=itdadao&utm_medium=referral . 同时修改文件 ...

  2. 如何将QT的pro图标修改的更显著一些

    如何将QT的pro图标修改的更显著一些 QT的项目打开文件是pro,默认是这样的 这个白色的背景在很多文件中很不好找 所以使用工具进行相关修改. 寻找到.pro 双击修改ico 默认的这个就非常不错. ...

  3. Win7 配置免安装mysql5.7.20过程详解

    转载:https://www.2cto.com/database/201406/312689.html 转载:http://blog.csdn.net/hekaihaw/article/details ...

  4. 理解Linux文件系统之 inode

    一.inode是什么? 理解inode,要从文件储存说起. 文件储存在硬盘上,硬盘的最小存储单位叫做”扇区”(Sector).每个扇区储存512字节(相当于0.5KB). 操作系统读取硬盘的时候,不会 ...

  5. ODAC(V9.5.15) 学习笔记(三)TOraSession(3)

    3. 选项 TOraSession的Options有如下内容 名称 类型 说明 CharLength TCharLength 单个字符的长度,缺省0,表示从服务器获取对应的字符集中单个字符长度 Cha ...

  6. List of 3rd Party .NET UI & Reporting Components

    https://www.codeproject.com/Reference/788434/List-of-rd-Party-NET-UI-Reporting-Components Introducti ...

  7. C# 中2个问号的作用。C#的??代表是什么意思

    https://www.cnblogs.com/gggg/p/5867412.html 变量定义中含有一个问号,意思是这个数据类型是NullAble类型的.(NullAble意思是可以为空) 变量定义 ...

  8. 题解——洛谷P2827 NOIP提高组 2016 蚯蚓

    队列模拟 详细题解待填坑 #include <cstdio> #include <algorithm> #include <queue> #include < ...

  9. Torch 两个矩形框重叠面积的计算 (IoU between tow bounding box)

    Torch 两个矩形框重叠面积的计算 (IoU between tow bounding box) function DecideOberlap(BBox_x1, BBox_y1, BBox_x2, ...

  10. [HDU] 平方和与立方和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2007 //坑:注意判断输入两个数的前后大小关系 // 用while 循环 #include<io ...