一、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. php 带省略号的分页

    原文链接:https://blog.csdn.net/u011060253/article/details/25308455 $curpage = isset($_GET[; $page = new ...

  2. [内核驱动] VS2012+WDK 8.0 Minifilter实现指定扩展名文件拒绝访问

    转载:http://blog.csdn.net/C0ldstudy/article/details/51585708 转载:http://blog.csdn.net/zj510/article/det ...

  3. JS实现复制页面文字弹出消息提醒

    先上效果图: 简洁版: <script type="text/javascript"> document.body.oncopy=function(){ alert(& ...

  4. ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 45, found 42. Created with MySQL 50560, now running 50725. Please use mysql_upgrade to fix this error.

    centos7.5 登入mysql,进行授权报错 问题: mysql> grant all privileges on *.* to 'lvhanzhi'@'%' identified by ' ...

  5. topcoder srm 698 div1 -3

    1.定义重复串$S=T+T$,即$S$可以表示成一个串的叠加.给定一个串$s$,可以通过删除字符.修改字符.增加字符来使得其变为重复串.问最少的次数. 思路:首先将$s$分成个串$s_{0},s_{1 ...

  6. Web开发中B/S架构和C/S架构的区别

    在web开发中有两种基本架构,即C/S架构和B/S架构那么这两种架构有什么区别呢?那么就一起来看看吧. C/S架构图: B/S架构图: C/S架构是 浏览/服务器端的交互,是早期的一种分布式架构,在该 ...

  7. Flash Memory 简介【转】

    本文转载自:https://linux.codingbelief.com/zh/storage/emmc/ Flash Memory 是一种非易失性的存储器.在嵌入式系统中通常用于存放系统.应用和数据 ...

  8. html 之 img hspace 和 vspace 属性

    案例<img src="w3school.gif" hspace="30" vspace="30" /> 描述 通常图形浏览器不 ...

  9. P3605 [USACO17JAN]Promotion Counting晋升者计数

    思路 线段树合并的板子.. 和子节点合并之后在值域线段树上查询即可 代码 #include <cstdio> #include <algorithm> #include < ...

  10. Hierarchical Question-Image Co-Attention for Visual Question Answering

    Hierarchical Question-Image Co-Attention for Visual Question Answering NIPS 2016 Paper: https://arxi ...