Guest User

Untitled

a guest
Feb 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. var session
  2. var credentials
  3. var resp
  4.  
  5. function encodeBasicAuthorizationCredentials(options = {}) {
  6. return 'Basic ' + btoa(options.username + ":" + options.password)
  7. }
  8.  
  9. function setCredentials(options = {}) {
  10. credentials = encodeBasicAuthorizationCredentials(options)
  11. }
  12.  
  13. function getSession() {
  14. fetch("/api/session", { method: 'GET', headers: { 'Authorization': credentials } })
  15. .then(function(response) {
  16. response.json().then(function(json) { session = json })
  17. });
  18. }
  19.  
  20. function setSession(data) {
  21. var request = new Request("/api/session", {
  22. method: 'POST',
  23. body: JSON.stringify(data),
  24. headers: {
  25. 'Authorization': credentials
  26. }
  27. });
  28. fetch(request).then(function(response) {
  29. response.json().then(function(json) { resp = json })
  30. });
  31. }
  32.  
  33. setCredentials({ username: "bcap", password: "bcap" })
  34.  
  35. data = {"cmd":"net.probe on"}
  36.  
  37. setSession(data)
Add Comment
Please, Sign In to add comment