Http Requests for PHP
2015-11-06 11:03
465 查看
一、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、引用类库文件
?
4、让程序自动引用相关内部类库(一定要执行这行代码)
?
5、开始使用GET或POST请求获取远程数据
?
常用方法说明:
1、使用GET发送请求获取远程数据 Requests::get($url, $headers = array(), $options = array());
这里有3个参数可以使用
第1个参数:$url 为需要获取远程数据的url链接,例如:
?
第2个参数:$headers = array() 为附加的头部请求
?
第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.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、引用类库文件
?
?
?
1、使用GET发送请求获取远程数据 Requests::get($url, $headers = array(), $options = array());
这里有3个参数可以使用
第1个参数:$url 为需要获取远程数据的url链接,例如:
?
?
`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() 为表单提交的数据
相关文章推荐
- zigbee网关 利用现有的网络实现全球控制
- 技术向:一文读懂卷积神经网络
- HttpURLConnection Get和Post发送数据
- iOS9默认加载Https协议的相关设置
- SOKECT5 代理服务器协议 TCP
- Linux Netfilter中修改TCP/UDP Payload的方法
- 网络进销存系统
- 五个好用的网络协议分析工具(附下载地址)
- 解决ubuntu svn checkout https问题
- 打造安全的App!iOS安全系列之 HTTPS 进阶
- 【读书笔记】iOS网络-错误处理的经验法则
- 【读书笔记】iOS网络-错误处理的经验法则
- Android网络编程中的URLConnection的IP设定
- WCF中NetTCp配置
- HttpServletRequest类既有getAttribute()方法,也有getParameter()方法,有setAttribute()方法,而没有setParameter()方法
- winform版简易http服务器
- nodejs http小爬虫
- AFN框架实现简单的网络状态监测以及支持https安全证书
- java网络编程之下载文件通过多线程分块下载(二)
- 黑马程序员—Java基础—网络编程2