php curl 擴充套件使用

2021-07-28 15:48:59 字數 1331 閱讀 5662

1.curl介紹

curl 是乙個利用url語法規定來傳輸檔案和資料的工具,支援很多協議,如http、ftp、telnet等。最爽的是,php也支援 curl 庫。本文將介紹 curl 的一些高階特性,以及在php中如何運用它。

2.基本結構

在學習更為複雜的功能之前,先來看一下在php中建立curl請求的基本步驟:

(1)初始化

curl_init()

(2)設定變數

curl_setopt() 。最為重要,一切玄妙均在此。有一長串curl引數可供設定,它們能指定url請求的各個細節。要一次性全部看完並理解可能比較困難,所以今天我們只試一下那些更常用也更有用的選項。

(3)執行並獲取結果

curl_exec()

(4)釋放curl控制代碼

curl_close()

3.curl實現get和post

3.1 get方式實現

//初始化

$ch = curl_init();

//設定選項,包括url

curl_setopt($ch, curlopt_url, "");

curl_setopt($ch, curlopt_returntransfer, 1);

curl_setopt($ch, curlopt_header, 0);

//執行並獲取html文件內容

$output = curl_exec($ch);

//釋放curl控制代碼

curl_close($ch);

//列印獲得的資料

print_r($output);

3.2 post方式實現

// post資料

curl_setopt($ch, curlopt_post, 1);

// post的變數

curl_setopt($ch, curlopt_postfields, $post_data);

$output = curl_exec($ch);

curl_close($ch);

//列印獲得的資料

print_r($output);

php curl擴充套件不能使用

用的php 7.1.3 curl模組無法使用 環境是是自己配的.在php.ini中,查詢extension php curl.dll 找到後把它前面的分號去掉.如圖 然後再查詢extension dir 配置它的路徑指向php curl.dll 模組對應的資料夾.再然後把libeay32.dll,s...

安裝php cURL擴充套件

curl官網 以下方法在ubuntu下沒有嘗試成功,sudo apt get install php5,找不到下文所謂php原始碼目錄安裝在 後來發現sudo apt get install php5 curl即可安裝php curl擴充套件。以下文章以後再研究 今天又重新裝了一下,貌似下面的步驟還...

怎樣使用php curl擴充套件進行多執行緒post資料

怎樣使用php curl擴充套件進行多執行緒post資料 curl 是使用url語法的傳送檔案工具,支援ftp ftps http htpps scp sftp tftp telnet dict file和ldap。curl 支援ssl證書 http post http put ftp 上傳,ker...