This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

HTTP GET with authorisation
#1
Hello,

I want integrate with Traccer server. This server give the JSON when I log in and brows such address:
http://demo.traccar.org/api/positions/


But for LM communication I must have some authorisation. What should I add to this script?

Code:
-- load required modules
http = require("socket.http")
mime = require("mime")

-- Alternatively, one could fill the appropriate header and authenticate
-- the request directly.
r, c, d, e = http.request {
  url = "http://demo.traccar.org/api/positions/",
  headers = { authorization = "Basic " .. (mime.b64("login:password")) }
}

log(r,c,d,e)
Now it gives:

Code:
* arg: 1
 * number: 1
* arg: 2
 * number: 200
* arg: 3
 * table:
  [server]
   * string: Jetty(9.2.19.v20160908)
  [content-type]
   * string: application/json
  [connection]
   * string: close
  [content-length]
   * string: 393
  [access-control-allow-headers]
   * string: origin, content-type, accept, authorization
  [access-control-allow-origin]
   * string: *
  [date]
   * string: Sat, 29 Oct 2016 22:39:46 GMT
  [access-control-allow-credentials]
   * string: true
  [access-control-allow-methods]
   * string: GET, POST, PUT, DELETE, OPTIONS
* arg: 4
 * string: HTTP/1.1 200 OK

[b]Traccar[/b] 30.10.2016 00:39:27
* arg: 1
 * number: 1
* arg: 2
 * number: 200
* arg: 3
 * table:
  [server]
   * string: Jetty(9.2.19.v20160908)
  [content-type]
   * string: application/json
  [connection]
   * string: close
  [content-length]
   * string: 393
  [access-control-allow-headers]
   * string: origin, content-type, accept, authorization
  [access-control-allow-origin]
   * string: *
  [date]
   * string: Sat, 29 Oct 2016 22:39:27 GMT
  [access-control-allow-credentials]
   * string: true
  [access-control-allow-methods]
   * string: GET, POST, PUT, DELETE, OPTIONS
* arg: 4
 * string: HTTP/1.1 200 OK

Login is an email so it has '@'.
Reply


Messages In This Thread
HTTP GET with authorisation - by buuuudzik - 29.10.2016, 22:11
RE: HTTP GET with authorisation - by admin - 31.10.2016, 07:44
RE: HTTP GET with authorisation - by edgars - 15.11.2016, 13:44

Forum Jump: