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 然后,尝试 ...
随机推荐
- libopencv_shape.so.3.0: cannot open shared object file: No such file or directory 解决笔记
进入目录:/etc/ld.so.conf.d 创建:opencv.conf 添加:/opt/opencv-3.0.0/build/lib 执行:ldconfig DETAIL: (1)ldd dlsd ...
- 20155201 李卓雯 《网络对抗技术》实验一 逆向及Bof基础
20155201 李卓雯 <网络对抗技术>实验一 逆向及Bof基础 一.实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,f ...
- Received empty response from Zabbix Agent at[172.16.1.51]. Assuming that agent dropped connection because of access permissions
Centos7.5 Zabbix创建主机ZBX爆红 原因:/etc/zabbix/zabbix_agentd.conf配置文件的Server写错了 解决方法: [root@db01 ~]# vim / ...
- Bootstrap3基础 img-responsive 响应式图片
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- thinkphp留言板开发笔记 1 - 新的
关于php数组的排序函数的总结: 有很多种排序方式和排序规则: 正常排序和反向排序, 使用 -r来表示 排序时是否考虑索引/下标, 如果考虑则加上-a, a=associate. sort是按值来排序 ...
- (转)renren-fast解读(二)
(二期)9.renren-fast项目解读(二) [课程九]jwt.xmind36.4KB [课程九]动态数据源.xmind0.2MB JWT 概要 JWT是一种用于双方之间传递安全信息的简洁的.UR ...
- IDEA引入Gradle工程小记
1.首先IDEA要在该工程Settings中配置本地安装的Gradle,配好其home目录,注意目录到根目录即可,不要到bin一级,否则提示错误,无法使用: 2.配置好后会自动侦测Gradle项目,点 ...
- Docker7之Docker overview
Docker is an open platform for developing, shipping, and running applications. Docker enables you to ...
- Linux下 网卡测速
参考: How do I verify the speed of my NIC? Linux下 网卡测速 命令: $ sudo ethtool eth0 Settings for eth0: Supp ...
- AngularJS 笔记2
2017-03-23 本文更新链接: http://www.cnblogs.com/daysme/p/6613071.html $http angularjs中的ajax 向服务器请求数据 1/2 后 ...