If the site does not use basic HTTP authentication, but uses an HTML form to authenticate the user, and you do not have access to the developers of the site, the best way to find out what is happening is to look in which browser.
Launch Firebug or Google Chrome Developer Tools or an HTTP proxy.
Open the site in your browser, log in and see what requests the browser made for this, and what the answers on the site answered. You must imitate the same queries in your program.
Please note that, most likely, the website will require you to send session information in subsequent requests in order to maintain authentication. This may be a cookie (or several) and / or GET. Once again, let's see what the browser does and emulates.
As for the format - searching for examples on the Internet, there are several.
Update: OK, here is an example.
Please note that the URL used in the example will expire soon. Just create your own http://requestb.in/ . Open http://requestb.in/vbpkxivb?inspect in a browser to find out what data your program transmitted. Do not send a real username and password for this service!
require 'socket.http' local request_body = [[login=user&password=123]] local response_body = { } local res, code, response_headers = socket.http.request { url = "http://requestb.in/vbpkxivb"; method = "POST"; headers = { ["Content-Type"] = "application/x-www-form-urlencoded"; ["Content-Length"] = #request_body; }; source = ltn12.source.string(request_body); sink = ltn12.sink.table(response_body); } print("Status:", res and "OK" or "FAILED") print("HTTP code:", code) print("Response headers:") if type(response_headers) == "table" then for k, v in pairs(response_headers) do print(k, ":", v) end else -- Would be nil, if there is an error print("Not a table:", type(response_headers)) end print("Response body:") if type(response_body) == "table" then print(table.concat(response_body)) else -- Would be nil, if there is an error print("Not a table:", type(response_body)) end print("Done dumping response")
Expected Result:
Status: OK
HTTP code: 200
Response headers:
date: Sat, 23 Jun 2012 07:49:13 GMT
content-type: text / html; charset = utf-8
connection: Close
content-length: 3
Response body:
ok
Done dumping response