-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToken_test_chatbot.html
More file actions
53 lines (44 loc) · 1.38 KB
/
Token_test_chatbot.html
File metadata and controls
53 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Barter Token Authentication</title>
</head>
<body>
<h2>Barter Token Authentication</h2>
<div id="authResponse"></div>
<script>
var xhr = new XMLHttpRequest();
// Prepare the request
xhr.open("POST", "https://192.168.3.80:443/api/5.0/auth/login", true);
xhr.setRequestHeader("Content-Type", "application/json");
// Define the data to be sent in the request body
var data = JSON.stringify({
username: "Admin",
password: "Admin"
});
// Set up a function to handle the response
xhr.onload = function () {
// Check if the request was successful
if (xhr.status >= 200 && xhr.status < 300) {
// Parse the response JSON
var response = JSON.parse(xhr.responseText);
// Access the access token from the response
var accessToken = response.access_token;
// Use the access token as needed
document.getElementById('authResponse').textContent = 'Access Token:' + accessToken;
} else {
// Request failed
document.getElementById('authResponse').textContent = 'Request failed with status:' + xhr.status;
}
};
// Set up a function to handle errors
xhr.onerror = function () {
console.error("Request failed");
};
// Send the request with the data
xhr.send(data);
</script>
</body>
</html>