使用curl獲取資料

2021-06-16 04:17:35 字數 510 閱讀 9593

在工作中需要獲取別人提供的介面,於是使用curl來獲得資料,下面是簡單例子:

$curl

= curl_init

(); //初始化

curl_setopt

($curl

,curlopt_url

, $url

); //設定訪問位址

curl_setopt

($curl

,curlopt_timeout,3

);    //設定等待時間為3秒

curl_setopt

($curl

,curlopt_returntransfer

,true

);  //設定返回到變數裡面,否則直接輸出

$data = curl_exec($curl);

curl_close($curl)

php 使用 CURL 獲取資料

第一種,post 和 get 合併 output curl exec cl 執行 curl 會話 curl close cl return output 第二種 post 和 get分開post post資料 curl setopt ch,curlopt post,1 curl setopt ch,...

php 使用 CURL 獲取資料

第一種,post 和 get 合併 執行 curl 會話 curl close cl return output 第二種 post 和 get分開 post資料 curl setopt ch,curlopt post,1 curl setopt ch,curlopt ssl verifypeer,f...

php使用curl提交獲取資料

用了多次curl後整合出來的,支援多種操作 url arrip 如果有 ip 格式array curlpost 需要post提交資料 header header資料 user agent 模擬瀏覽器訪問 public function curl url,curlpost false,header f...