* [ ] Curl使用說明
```
new \Curl($data);
```
data(array):curl公共配置(詳細參數請看類)
* [ ] 連貫操作
~~~
//多線程
$curl=new \Curl(array);
$curl->url('https://ip138.com')->coding('utf8', 'gb2312')->save(); //使用save保存設置
$curl->url('https://baidu.com')->save();//使用save保存設置
$data=$curl->exec(); //使用exec執行,返回數組
echo $data[0];
echo $data[1];
//多線程
$curl=new \Curl(array);
$curl->url('https://ip138.com')->coding('utf8', 'gb2312')->save('ip138'); //使用save保存設置
$curl->url('https://baidu.com')->save('baidu');//使用save保存設置
$data=$curl->exec(); //使用exec執行,返回數組
echo $data['ip138'];
echo $data['baidu'];
//單線程
$curl=new \Curl(array);
echo $curl->url('https://ip138.com')->coding('utf8', 'gb2312')->exec(); //方法1
echo $curl->url('https://ip138.com')->coding('utf8', 'gb2312')->exec(true); //方法2
//靜態方法(參數請看類)
echo \Curl::call(['url'=>'https://ip138.com','coding'=>['utf8', 'gb2312']]);
// 代理IP
$ip = [
"status" => false,
"ip" => "x.x.x.x",
"port" => "xxxx",
"userpass" => "xxxx:xxx",
"type" => "HTTP",
"auth" => "BASIC",
];
$curl = new \Curl(["ip" => $ip]);
// 使用代理ip
$curl->url("http://xxxx.com")->ip(true)->save('a');
// 不適用代理ip
$curl->url("http://xxxx.com")->ip(false)->save('b');
// 執行請求
$data = $curl->exec();
$a = ['ip' => Curl::headKey($data['a'], '\"\>', '\<'), 'address' => Curl::headKey($data['a'], '來自:')];
$b = ['ip' => Curl::headKey($data['b'], '\"\>', '\<'), 'address' => Curl::headKey($data['b'], '來自:')];
//靜態方法
1.通過名稱獲取指定頭部信息
headkey($header, $start, $end = ''); //header=內容,start=起始字符串,end=結尾字符串
2.獲取頭部內容 (遠程獲取內容時,頭部信息和內容一起時,可通過此方法獲取單獨獲取頭部信息)
gethead($data); //data=內容
3.獲取body內容 (遠程獲取內容時,頭部信息和內容一起時,可通過此方法獲取單獨獲取body)
getbody($data);//data=內容
4.分離頭部和body內容成array (遠程獲取內容時,頭部信息和內容一起時,可通過此方法分離)
headbody($data);//data=內容
~~~
* [ ] 公共參數配置說明
*****
| 參數名 | 數據類型 | 默認值 | 參數說明 | 對應 curl 屬性 |
| --- | --- | --- | --- | --- |
| url | string | null | 設置請求地址(必選) | |
| time | int | 10 | 設置超時時間,單位為秒 | CURLOPT_CONNECTTIMEOUT |
| zip | string | null | 解壓縮gzip (gzip,deflate) | CURLOPT_ENCODING |
| export | boolean | true| true 成功只將結果返回,不自動輸出任何內容, false 成功只返回TRUE,自動輸出返回的內容 | CURLOPT_RETURNTRANSFER |
| sslpeer| boolean | false | 是否檢查證書,false 不檢查,true 檢查 | CURLOPT_SSL_VERIFYPEER |
| sslhost | int | 2 | 1 檢查服務器SSL證書中是否存在一個公用名(common name)。譯者注:公用名(Common Name)一般來講就是填寫你將要申請SSL證書的域名 (domain)或子域名(sub domain) 2 檢查公用名是否存在,并且是否與提供的主機名匹配 | CURLOPT\_SSL\_VERIFYHOST |
| jump | boolean | false | 是否自動跳轉 | CURLOPT_FOLLOWLOCATION |
| ifhead | boolean | false | 是否返回頭部信息 | CURLOPT_HEADER |
| ifbody | boolean | false | 是否返回body信息 | CURLOPT_NOBODY |
| agent | string | $_SERVER['HTTP_USER_AGENT']) 的值或 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; | 設置HTTP請求中包含一個*"User-Agent: "*頭的字符串 | CURLOPT_USERAGENT |
| referer | string 或 boolean | false | 是否設置 referer | CURLOPT_AUTOREFERER、CURLOPT_REFERER |
| ip | boolean 或 array | [] | 設置代理通道 ,如果傳入數組,結構為:["status" => "boolean,true開啟代理,false不開啟代理,可通過ip方法動態設置開啟關閉代理狀態","ip" => "代理IP地址","port" => "代理端口號", "userpass" => "代理賬號:密碼,username:password的格式", "type":"設置CURLOPT_PROXYTYPE,可選值:HTTP,SOCKS5","auth" => "設置CURLOPT_PROXYAUTH ,可選值:BASIC,NTLM"] | CURLOPT_PROXY、CURLOPT_PROXYPORT、CURLOPT_PROXYUSERPWD、CURLOPT_PROXYTYPE、CURLOPT_PROXYAUTH |
| cookie | string 或 boolean | false | 設定HTTP請求中*"Cookie: "*部分的內容。多個cookie用分號分隔,分號后帶一個空格(例如, "*fruit=apple; colour=red*") | CURLOPT_COOKIE |
| mode | string | GET| 請求方式 GET、POST、PUT、DELETE | CURLOPT_CUSTOMREQUEST、CURLOPT_POST |
| data | array 或 string | []| 請求的數據,如果請求方式為GET,會自動將data拼接到url參數里面 | CURLOPT_POSTFIELDS、CURLOPT_URL |
| head | array| []| 設置請求頭,例['X-Requested-With: XMLHttpRequest',''] | CURLOPT_HTTPHEADER |
| coding | array 或 string | []| 結果數據編碼轉換,[to, from], 從from編碼格式轉換為to的編碼格式 | 無 |
| arr | boolean|true| json數據轉為數組或者對像(true=數組,false=對像),只有數據為json才會生效 | 無 |
| json | boolean| false | 是否json提交(get不支持json),請求頭新增:Content-Type: application/json;Content-Length:xxx | 無 |
| ajax | boolean | false | 是否ajax提交,請求頭新增:X-Requested-With: XMLHttpRequest | 無 |
| text | boolean | false | 是否文本提交 (get不支持text)| 無 |
| file | string | false | 保存的文件名| 無 |
- 開始使用
- 配置文件
- 路由模式
- AutoLoad類
- 啟動文件
- __construct
- SetRouting
- SetAlias
- SetStop
- SetError
- Access
- SetWorker
- SetClassFile
- SetClassDir
- Run
- OpenLoad
- LinuxStartAll
- Session類
- 使用說明
- set
- get
- delete
- pull
- has
- id
- Cookie類
- 使用說明
- set
- get
- delete
- pull
- has
- TempLets類
- 模板語法
- 模板標簽
- html
- show
- assign
- obtain
- Request類
- get
- post
- host
- referer
- getip
- localip
- header
- body
- file
- scheme
- protocolversion
- uri
- path
- querystring
- method
- Response
- SendFile
- FileStream
- SendData
- SetStatus
- SetHead
- SetMime
- WebSend
- redirect
- dumpJson
- dump
- come
- ps
- Frame類
- GetWeb
- ViewFile
- RoutingData
- SetClassFile
- SetClassDir
- GetMime
- FileMime
- LoadDir
- StartDir
- IsJson
- ArrJson
- JsonFormat
- ObStart
- GetConfig
- ConfigDir
- TempDir
- GetRunData
- GetStatic
- IsDebug
- SetDebug
- GetDebugInfo
- GlobalVariables類
- 使用說明
- set
- get
- delete
- pull
- has
- id
- Mysql類
- 新版本
- 第三方
- Thinkorm
- Medoo
- 舊版本
- Mysql 配置格式
- 項目中操作數據庫
- 項目場景
- 項目數據庫配置
- 項目數據庫中間類
- 項目中操作數據表
- 連貫操作
- where
- table
- data
- order
- field
- limit
- page
- group
- having
- join
- tabname
- union
- sql
- link
- link_base
- lock
- CURD 操作
- 寫入數據
- 數據刪除
- 數據查詢
- 數據更新
- 數據統計操作
- count
- sum
- max
- min
- avg
- 操作DEMO
- CurdTrait.php
- 項目Model層操作表.md
- Curl類
- Method類
- SslAes類
- layui_zqadmin