0%

Laravel send a request with Guzzle

安裝套件

Composer require guzzlehttp/guzzle

使用方法

use GuzzleHttp\Client;
$client = new Client();

GET

$response_origin = $client->request('GET', url);

POST

1
2
3
4
5
$response_origin = $client->request('POST', url, 
['form_params' => [
"userID"=>$request->user_id,
"key"=>$request->key]
]);

$response = json_decode($response_origin->getBody())
$data = $response->data