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

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

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

情介紹

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

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

requests for php如何使用:

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

把lipary目錄重名稱(chēng)為requests,然后拷貝到程序的類(lèi)庫(kù)文件夾

3、引用類(lèi)庫(kù)文件

require_once ('requests/Requests.php');

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

Requests::register_autoloader();

5、開(kāi)始使用GET或POST請(qǐng)求獲取遠(yuǎn)程數(shù)據(jù)

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

var_dump($response);

requests for php常用方法說(shuō)明:

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

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

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

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

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

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

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

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

(integer, seconds, default: 10)

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

(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ā)送請(qǐng)求獲取遠(yuǎn)程數(shù)據(jù) Requests::post($url, $headers = array(), $data = array(), $options = array());

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

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

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

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

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

載地址

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

網(wǎng)友評(píng)論

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