对象 tf_restful_client 是用来操作 RESTFul 风格接口的客户端
对象 tf_restful_client 自带编码转换,得到的结果数据就是本地编码
对象 tf_restful_client 支持HTTP Basic和OAuth2验证方式,可以自动完成验证操作
tf_restful_client 对象在 common.common_restful 位置
linking('common.common_restful')
修饰:public
说明:用于开启调试模式,一般情况下设置为 3 即可
参数:
$pageObj:page_info 对象实例
$opts = null:选项参数
介绍
获取最近一次请求的HTTP状态码
介绍
获取最近一次请求的HTTP状态信息
介绍
设置HTTP Basic方式的认证参数
参数:
$user:认证用户名
$pwd:认证密码
介绍
设置HTTP Digest方式的认证参数
介绍
关闭HTTP认证
介绍
请求远程RESTFul地址
参数:
$url:接口请求地址
$method = null:接口请求方式(GET/POST/PUT/DELETE),默认 GET
$myPostData = null:POST数据,只在POST情况下有效
$myPostHeader = null:HTTP头信息数据
$dataFormatInput = null:输入数据格式(json/xml),默认 json
$dataEncodingInput = null:输入数据编码格式,默认 UTF-8
介绍
获取最近一次请求的请求信息
介绍
获取最近一次请求的响应信息
介绍
设置超时时间
参数:
$secs:超时时间的秒数
完成对接口 http://tongfu.net/api/user 的插入数据操作
$myRestfulObj = new tf_restful_client($this->pageObj); $myRestfulObj->debug = 3; $result = $myRestfulObj->doAction("http://tongfu.net/api/user", "POST", array( 'name'=>"张三", 'pwd'=>"123456", ));
我们通过接口对刚刚写入的用户进行查询
$myRestfulObj = new tf_restful_client($this->pageObj); $myRestfulObj->debug = 3; $result = $myRestfulObj->doAction("http://tongfu.net/api/user", "GET");
我们通过客户端对象完成带HTTP Basic认证的请求
$myRestfulObj = new tf_restful_client($this->pageObj); $myRestfulObj->debug = 3; $myRestfulObj->setHTTPAuthBasic("admin","123456"); $result = $myRestfulObj->doAction("http://tongfu.net/api/user", "GET");
我们主观认为服务器端返回的数据一定是 UTF-8 编码格式的,除非有提供 Content-Type: application/json; charset=xxx 特别说明
无论服务器端返回的是何种编码,在请求结束后都会根据 PHP_CHARSET 设定转换为本地编码格式
我们主观认为服务器端接收的数据一定是 UTF-8 编码格式的,除非通过 $dataEncodingInput 参数特别指定