If the site does not use a HTTP basic auth, but uses a HTML form to autentificate user, and you have no access to the site developers, the best way to figure out what is going on is to peek at what browser does.
Fire up your Firebug or Google Chrome Developer Tools, or some HTTP debugging proxy.
Open the site in your browser, log in, and look at what requests browser did to do that, and what were the site's replies. You have to imitate same requests in your program.
Note that most likely the website will require you to send session information in subsequent requests to keep authenticated. It may be a cookie (or several) and / or a GET parameter. Again, look at what browser does and imitate.
As for format — search for examples on the web, there are a few.
Update: OK, here is an example.
Note that URL used in example will expire soon. Just create your own at http://requestb.in/. Open http://requestb.in/vbpkxivb?inspect in browser to see what data your program sent. Do not send real login and password to 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 output:
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