niammuddin icon

rest api mikrotik guzzlehttp di codeigniter 3

niammuddin | PRO | 08/16/22 12:48:16 AM UTC (Edited) | 0 ⭐ | 1564 👁️ | Never ⏰ | []
PHP |

1.09 KB

|

None

|

0 👍

/

0 👎

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
use GuzzleHttp\Client;
 
class ROS_model extends CI_model
{
    private $_client;
    public function __construct()
    {
        $this->_client = new Client([
            'base_uri' => 'https://10.10.33.21/rest/',
            'auth' => ['admin', 'admin'],
            'verify' => false
        ]);
    }
 
    public function IP_address()
    {
        $response = $this->_client->request('GET', 'ip/address');
        $body = $response->getBody();
        $result = json_decode($body, true);
        print_r($result);
    }
 
    public function AddPPP()
    {
        $response = $this->_client->request('PUT', 'ppp/secret', [
    
        'headers' => ['Content-type: application/json'],
        'body' => json_encode(
            array(
                'name' => 'test',
                'password' => '123',
                'profile' => 'default'
            )
        ),
    ],
    );
        $body = $response->getBody();
        $result = json_decode($body, true);
        print_r($result);
    }

Comments