lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


You need a cookie management module like this:
https://github.com/aryajur/luacookie

It can be used something like this:

        lc = require("luacookie")
local cm = lc.new()
-- Login 
local hdrs,msg,resp, URI
URI = [[http://www.design-reuse.com/login2.php]]
print("Try connection to "..URI)
-- Got the form fill details from the chrome developer console
local b,c,l,h = http.request(URI ,formencode({
go = "ok",
nexturl = [[http://www.website.com/]] ,
username = [[username]] ,
password = [[La8TZmMc]] ,
autolog = "X"
}))
if not b then
print("Error making connection: "..tostring(c))
return
end
hdrs,msg = cm.add(l,URI)
local ft = {}
print("Try the check login url with the cookie.")
URI = l.location
hdrs, msg = cm.getCookieHeader(URI)
if not hdrs then return nil,msg end
resp = {http.request{
url = "">
sink = ltn12.sink.table(ft),
headers = hdrs
}
}
print("Done with the http request.")
if not resp[1] then 
return nil,resp[2]
end


So basically you create a new cookie manager (cm) and then after each request just pass the header table to the add function in the cookie manager and then in the next request get the header using getCookieHeader function of the cookie manager. This has worked for me in the past few occasions requiring cookie management for websites that require login.



On Wed, Jun 27, 2018, 9:10 AM Dirk Laurie <dirk.laurie@gmail.com> wrote:
There is a package on Luarocks called lua-curl. With it, I can surf
the Internet form inside my Lua program.

Or so I thought. After all, all that Firefox and friends do is to send
a URL with everything you are communicating to a server and displaying
or otherwise utilizing the stuff it sends back.

I found that I could do general surfing thta way but did not succeed
in logging in to a site on which I am a registered user.

Maybe this is off-topic for this list. But maybe someone has used
lua-curl and knows what to do.