Http Requests for PHP
一、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的更多相关文章
- requests的content与text导致lxml的解析问题
title: requests的content与text导致lxml的解析问题 date: 2015-04-29 22:49:31 categories: 经验 tags: [Python,lxml, ...
- requests源码阅读学习笔记
0:此文并不想拆requests的功能,目的仅仅只是让自己以后写的代码更pythonic.可能会涉及到一部分requests的功能模块,但全看心情. 1.另一种类的初始化方式 class Reques ...
- Python爬虫小白入门(二)requests库
一.前言 为什么要先说Requests库呢,因为这是个功能很强大的网络请求库,可以实现跟浏览器一样发送各种HTTP请求来获取网站的数据.网络上的模块.库.包指的都是同一种东西,所以后文中可能会在不同地 ...
- 使用beautifulsoup与requests爬取数据
1.安装需要的库 bs4 beautifulSoup requests lxml如果使用mongodb存取数据,安装一下pymongo插件 2.常见问题 1> lxml安装问题 如果遇到lxm ...
- python爬虫学习(6) —— 神器 Requests
Requests 是使用 Apache2 Licensed 许可证的 HTTP 库.用 Python 编写,真正的为人类着想. Python 标准库中的 urllib2 模块提供了你所需要的大多数 H ...
- ImportError: No module named 'requests'
补充说明: 当前环境是在windows环境下 python版本是:python 3.4. 刚开始学习python,一边看书一边论坛里阅读感兴趣的代码, http://www.oschina.net/c ...
- Python-第三方库requests详解
Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...
- Requests 乱码
当使用Requests请求网页时,出现下面图片中的一些乱码,我就一脸蒙逼. 程序是这样的. def getLinks(articleUrl): headers = { "Uset-Agent ...
- 爬虫requests模块 2
会话对象¶ 会话对象让你能够跨请求保持某些参数.它也会在同一个 Session 实例发出的所有请求之间保持 cookie, 期间使用 urllib3 的 connection pooling 功能.所 ...
- 爬虫requests模块 1
让我们从一些简单的示例开始吧. 发送请求¶ 使用 Requests 发送网络请求非常简单. 一开始要导入 Requests 模块: >>> import requests 然后,尝试 ...
随机推荐
- BSGS算法学习笔记
从这里开始 离散对数和BSGS算法 扩展BSGS算法 离散对数和BSGS算法 设$x$是最小的非负整数使得$a^{x}\equiv b\ \ \ \pmod{m}$,则$x$是$b$以$a$为底的离散 ...
- 【Python56--爬取妹子图】
爬取网站的思路 第一步:首先分析爬取网站的连接地址特性,发现翻页图片的时候连接:http://www.mmjpg.com/mm/1570 ,http://www.mmjpg.com/mm/1569, ...
- 标签无效 "/zabbix_export/date": "YYYY-MM-DDThh:mm:ssZ" 预计。
Centos7.5 使用导入percona模板的时候报错 百度给的解决方案是 将zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1. ...
- topcoder srm 687 div1
1.$A_{1}=2,A_{2}=3,A_{n}=A_{n-2}+A_{n-1}-1$.给出数字$n$,将其表示成若干个$A$中的不同元素的和. 思路:设$B_{n}=A_{n}-1$,那么有$B_{ ...
- uniGUI试用笔记(九)
uniGUI执行程序部署有3种形式 1.ISAPI模式 部署在IIS或Apache,程序编译为Dll形式,没有试,准备后续专门测试一下. 2.标准执行文件模式 将软件编译成一个独立的Exe文件,包括了 ...
- CSS的再深入(更新中···)
在上一章我们提到了一个新的概念,叫做块级样式,讲到这里就要科普一下: 标签又分为两种: (1)块级标签 元素特征:会独占一行,无论内容多少,可以设置宽高··· (2)内敛标签(又叫做行内标签) 元素特 ...
- Spring Boot 项目中常见注解
@Autowired 自动导入依赖的 Bean.byType方式.把配置好的 Bean拿来用,完成属性.方法的组装,它可以对类成员变量.方法及构造函数进行标注,完成自动装配的工作 import org ...
- Shiro学习笔记四(Shiro集成WEB)
这两天由于家里出了点事情,没有准时的进行学习.今天补上之前的笔记 -----没有学不会的技术,只有不停找借口的人 学习到的知识点: 1.Shiro 集成WEB 2.基于角色的权限控制 3.基于权限的控 ...
- RabbitMQ学习之延时队列
原帖参考:http://www.cnblogs.com/telwanggs/p/7124687.html?utm_source=itdadao&utm_medium=referral http ...
- [学习一个] Matlab GUI 学习笔记 Ⅰ
Matlab GUI 学习笔记 Ⅰ 1. Foreword Matlab 是严格意义上的编程语言吗?曾经有人告诉我他是通过 Matlab 学会了面对对象编程,我是不信的,但这依然不妨碍它在特殊领域的强 ...