requester
v1.5
發送get,post,put,補丁,刪除請求
在簡單數組中發送參數
簡單陣列發送標頭
請求自動記錄
錯誤記錄器
在不等待回复的情況下發送請求
composer require arashabedii/requester
# to enable request logging just pass $logger=true to send method
Request::send([string] url, [array] or [string] or [file context] params, [string] request type , [array] headers,[bool] logger);
require 'vendor/autoload.php';
發送獲取請求
<?php
use ArashAbedii Request ;
require ' ./vendor/autoload.php ' ;
#------------------------------SIMPLE GET REQUEST---------------------------
$ url = " https://reqres.in/api/users " ;
$ method = ' GET ' ;
$ params =[
' delay ' => 1 ,
];
$ headers =[
' Content-Type ' => ' application/json ' ,
];
$ logger = true ; //enable or diable logging requests
$ response =Request:: send ( $ url , $ params , $ method , $ headers , $ logger );
//show headers
echo $ response -> headers ;
//show response body
echo $ response -> body ;發送發布請求
<?php
use ArashAbedii Request ;
require ' ./vendor/autoload.php ' ;
#------------------------------SIMPLE POST REQUEST---------------------------
$ url = " https://reqres.in/api/users " ;
$ method = ' POST ' ;
$ params =[
' name ' => ' myname ' ,
' job ' => ' myjob '
];
$ headers =[
' Content-Type ' => ' application/json ' ,
];
$ logger = false ; //enable or diable logging requests
$ response =Request:: send ( $ url , $ params , $ method , $ headers , $ logger );
//show headers
echo $ response -> headers ;
//show response body
echo $ response -> body ;發送PUT請求
<?php
use ArashAbedii Request ;
require ' ./vendor/autoload.php ' ;
#------------------------------SIMPLE PUT REQUEST---------------------------
$ url = " https://reqres.in/api/users/2 " ;
$ method = ' PUT ' ;
$ params =[
' name ' => ' myname2 ' ,
' job ' => ' myjob2 '
];
$ headers =[
' Content-Type ' => ' application/json ' ,
];
$ logger = false ; //enable or diable logging requests
$ response =Request:: send ( $ url , $ params , $ method , $ headers , $ logger );
//show headers
echo $ response -> headers ;
//show response body
echo $ response -> body ;發送補丁請求
<?php
use ArashAbedii Request ;
require ' ./vendor/autoload.php ' ;
#------------------------------SIMPLE PATCH REQUEST---------------------------
$ url = " https://reqres.in/api/users/2 " ;
$ method = ' PATCH ' ;
$ params =[
' name ' => ' myname2 ' ,
' job ' => ' myjob2 '
];
$ headers =[
' Content-Type ' => ' application/json ' ,
];
$ logger = false ; //enable or diable logging requests
$ response =Request:: send ( $ url , $ params , $ method , $ headers , $ logger );
//show headers
echo $ response -> headers ;
//show response body
echo $ response -> body ;發送刪除請求
<?php
use ArashAbedii Request ;
require ' ./vendor/autoload.php ' ;
#------------------------------SIMPLE DELETE REQUEST---------------------------
$ url = " https://reqres.in/api/users/2 " ;
$ method = ' DELETE ' ;
$ params =[
//no params or your params
];
$ headers =[
' Content-Type ' => ' application/json ' ,
];
$ logger = true ; //enable or diable logging requests
$ response =Request:: send ( $ url , $ params , $ method , $ headers , $ logger );
//show headers
echo $ response -> headers ;
//show response body
echo $ response -> body ;