Advertisement
niammuddin

rest api mikrotik guzzlehttp di codeigniter 3

Aug 15th, 2022 (edited)
1,231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. use GuzzleHttp\Client;
  5.  
  6. class ROS_model extends CI_model
  7. {
  8.     private $_client;
  9.     public function __construct()
  10.     {
  11.         $this->_client = new Client([
  12.             'base_uri' => 'https://10.10.33.21/rest/',
  13.             'auth' => ['admin', 'admin'],
  14.             'verify' => false
  15.         ]);
  16.     }
  17.  
  18.     public function IP_address()
  19.     {
  20.         $response = $this->_client->request('GET', 'ip/address');
  21.         $body = $response->getBody();
  22.         $result = json_decode($body, true);
  23.         print_r($result);
  24.     }
  25.  
  26.     public function AddPPP()
  27.     {
  28.         $response = $this->_client->request('PUT', 'ppp/secret', [
  29.    
  30.         'headers' => ['Content-type: application/json'],
  31.         'body' => json_encode(
  32.             array(
  33.                 'name' => 'test',
  34.                 'password' => '123',
  35.                 'profile' => 'default'
  36.             )
  37.         ),
  38.     ],
  39.     );
  40.         $body = $response->getBody();
  41.         $result = json_decode($body, true);
  42.         print_r($result);
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement