功能介绍
curl通讯类,包含 get、post 方式。
部署说明将 curl.php 文件直接部署到 phpGrace/tools/ 文件夹下
使用演示 - GET<?php
class indexController extends grace{
public function index(){
$curl = new phpGrace\tools\curl();
$res = $curl->get('http://api.hcoder.net');
//返回结果
echo $res;
}
}
使用演示 - POST<?php
class indexController extends grace{
public function index(){
$curl = new phpGrace\tools\curl();
//post 数据
$data = array('name' => 'grace', 'age' => 10);
$res = $curl->post('http://api.hcoder.net', $data);
//curl 状态
p($curl->http_status);
//传输时间毫秒
echo $curl->speed;
//返回结果
echo $res;
}
}
获取 curl 资源对象curl 资源对象保存在 phpGrace curl对象的 curlHandle 属性,您可以获取它并继续完成其他功能:$curlo = $curl->curlHandle;