75 lines
1.6 KiB
PHP
Executable File
75 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
// Define the API endpoint URL
|
|
$apiUrl = 'http://185.192.96.221:8081/jwt-api-token-auth/';
|
|
|
|
// Define the username and password
|
|
$username = 'admin';
|
|
$password = 'Mmm123321';
|
|
|
|
// Create an array of data to send as the request payload
|
|
$data = array(
|
|
'username' => $username,
|
|
'password' => $password,
|
|
);
|
|
|
|
// Encode the data as JSON
|
|
$jsonData = json_encode($data);
|
|
|
|
// Initialize cURL session
|
|
$ch = curl_init($apiUrl);
|
|
|
|
// Set cURL options
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
|
|
|
|
// Execute the request and capture the response
|
|
$response = curl_exec($ch);
|
|
|
|
// Check for cURL errors
|
|
if (curl_errno($ch)) {
|
|
echo 'cURL error: ' . curl_error($ch);
|
|
}
|
|
|
|
// Close the cURL session
|
|
curl_close($ch);
|
|
|
|
// Output the API response
|
|
$response = json_decode($response, true);
|
|
print_r($response);
|
|
|
|
|
|
|
|
// Define the API endpoint URL
|
|
$apiUrl = 'http://185.192.96.221:8081/personnel/api/employees/';
|
|
|
|
// Initialize cURL session
|
|
$ch = curl_init($apiUrl);
|
|
|
|
// Set cURL options
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
// Set the Authorization header with the JWT token
|
|
$jwtToken = $response['token'];
|
|
$headers = array(
|
|
'Content-Type: application/json',
|
|
'Authorization: ' . $jwtToken,
|
|
);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
// Execute the request and capture the response
|
|
$response = curl_exec($ch);
|
|
|
|
// Check for cURL errors
|
|
if (curl_errno($ch)) {
|
|
echo 'cURL error: ' . curl_error($ch);
|
|
}
|
|
|
|
// Close the cURL session
|
|
curl_close($ch);
|
|
|
|
// Output the API response
|
|
echo $response;
|