當(dāng)前位置:首頁 > 電腦軟件 > 程序源碼 > requests for php(PHP開發(fā)工具)

requests for php(PHP開發(fā)工具)

版本:v2.0.8 大?。?26K 語言:簡體中文 類別:程序源碼
  • 類型:國產(chǎn)軟件
  • 授權(quán):免費軟件
  • 更新:2023-11-07
  • 環(huán)境:Windows11,Windows10,Windows8,Windows7,WinXP
  • 本地下載
9
0% 0%

情介紹

requests是一個用PHP編寫的HTTP庫,遵循ISC開源協(xié)議,目前托管在GitHub上,該庫去帶了Python HTTP/1.1意外的一切工作,能夠開發(fā)人員和Web服務(wù)無縫的結(jié)合在一起,該庫沒有任何的依賴關(guān)系,你可以獨立在任何開發(fā)環(huán)境以外,也不需要相關(guān)的軟件進行配置,安裝方式也多種多樣。

你可以利用requests for php發(fā)送HEAD、GET、POST、PUT、DELETE和PATCH HTTP請求,并且簡化了發(fā)送請求,使得用戶能夠簡單的進行添加標(biāo)題,表單數(shù)據(jù),多部分文件和參數(shù)等等文件。其次該庫還適用于國際域名、身份驗證、自動壓縮gzip壓縮響應(yīng)等。從中可以看出requests是一款非常好用且強大的托管HTTP請求的標(biāo)簽。

requests for php如何使用:

1、下載壓縮后,得到如下文件

把lipary目錄重名稱為requests,然后拷貝到程序的類庫文件夾

3、引用類庫文件

require_once ('requests/Requests.php');

4、讓程序自動引用相關(guān)內(nèi)部類庫(一定要執(zhí)行這行代碼)

Requests::register_autoloader();

5、開始使用GET或POST請求獲取遠程數(shù)據(jù)

$response = Requests::get('https://github.com/timeline.json');

var_dump($response);

requests for php常用方法說明:

1、使用GET發(fā)送請求獲取遠程數(shù)據(jù) Requests::get($url, $headers = array(), $options = array());

這里有3個參數(shù)可以使用

第1個參數(shù):$url 為需要獲取遠程數(shù)據(jù)的url鏈接,例如:

$response = Requests::get('https://github.com/timeline.json');

第2個參數(shù):$headers = array() 為附加的頭部請求

array('Accept' => 'application/json')

第3個參數(shù):$options = array() 為配置參數(shù)

`timeout`: 設(shè)置響應(yīng)超時時間

(integer, seconds, default: 10)

`useragent`: 設(shè)置發(fā)送到服務(wù)器的用戶代理

(string, default: php-requests/$version)

`follow_redirects`: 是否允許3XX重定向

(boolean, default: true)

`redirects`: How many times should we redirect before erroring?

(integer, default: 10)

`blocking`: Should we block processing on this request?

(boolean, default: true)

`filename`: File to stream the body to instead.

(string|boolean, default: false)

`auth`: Authentication handler or array of user/password details to use for Basic authentication

(Requests_Auth|array|boolean, default: false)

`proxy`: Proxy details to use for proxy by-passing and authentication

(Requests_Proxy|array|boolean, default: false)

`idn`: Enable IDN parsing

(boolean, default: true)

`transport`: Custom transport. Either a class name, or a transport object. Defaults to the first working transport from

{@see getTransport()}

(string|Requests_Transport, default: {@see getTransport()})

`hooks`: Hooks handler.

(Requests_Hooker, default: new Requests_Hooks())

`verify`: Should we verify SSL certificates? Allows passing in a custom

certificate file as a string. (Using true uses the system-wide root

certificate store instead, but this may have different behaviour

across transports.)

(string|boolean, default: lipary/Requests/Transport/cacert.pem)

`verifyname`: Should we verify the common name in the SSL certificate?

(boolean: default, true)

2、使用POST發(fā)送請求獲取遠程數(shù)據(jù) Requests::post($url, $headers = array(), $data = array(), $options = array());

這里有4個參數(shù)可以使用,多了一個請求數(shù)據(jù)(相當(dāng)于表單提交的數(shù)據(jù)),其實get也有這個數(shù)據(jù),get請求直接附加在url上了

第1個參數(shù):$url 同get的第一個參數(shù)

第2個參數(shù):$headers = array() 同get的第2個參數(shù)

第4個參數(shù):$options = array() 同get的第3個參數(shù)

第3個參數(shù):$data = array() 為表單提交的數(shù)據(jù)

載地址

  • 電腦版
requests for php(PHP開發(fā)工具) v2.0.8

網(wǎng)友評論

0條評論
(您的評論需要經(jīng)過審核才能顯示)