首页›网络›Curl 请求执行
Curl 请求执行
exec / prepare / sendTo 与结果获取
方法清单
| 方法 | 签名 | 说明 |
|---|---|---|
exec | exec() | 执行请求 |
prepare | prepare() | 组装全部 curl 选项,返回 resource|false |
sendTo | static sendTo($url="",$method="",$params=[],$rsptype="",$timeout=0) | 静态快速发送:method 传 JSON/XML 时自动 POST+对应 data_type;rsptype="json" 返回数组 |
getResult | getResult($type="") | ""=body 字符串;"json"=数组;"object"=$this |
getResultJson | getResultJson() | JSON 数组结果 |
getCode | getCode() | HTTP 状态码 |
isSuccess | isSuccess() | 200-299 返回 true |
execResponseHead | execResponseHead() | 仅执行并返回响应头 |
典型用法
// 静态快速发送
$arr = \Kuoqi\Curl::sendTo("https://api.example.com/v1/order", "POST",
array("order_no" => "KQ001"), "json", 10);
// 完整流程
$curl = new \Kuoqi\Curl();
$curl->setUrl("https://example.com");
$curl->exec();
if($curl->isSuccess()){
echo $curl->getResult(); // body
$data = $curl->getResult("json"); // 解析 JSON
}
KuoqiPHP v1.05 · 离线静态文档 · 界面基于 KuoqiUI ·
返回首页