Code Example:
$user_id = 1;
$this->load->helper('url');
$headers = array('Accept' => 'application/json');
$options = array(
'auth' => array('admin', '1234'),
'verify' => false, // Disable SSL verification, this option value is insecure and should be avoided!
);
$data = array('name' => 'John', 'email' => 'john@example.com');
$request = Requests::post(site_url('api/example/users'), $headers, $data, $options);
$result = $request->body;
$status_code = $request->status_code;
$content_type = $request->headers['content-type'];
Result:
string(56) "{
"status": false,
"error": "Invalid API key "
}"
Status Code:
403
Content Type:
application/json; charset=utf-8