lualuasocket

Send Get to website with lua


i'm having a trouble with lua.

I need send a request to a website by GET and get the response from website.

Atm all i have is this:

local LuaSocket = require("socket")
client = LuaSocket.connect("example.com", 80)
client:send("GET /login.php?login=admin&pass=admin HTTP/1.0\r\n\r\n")
while true do
  s, status, partial = client:receive('*a')
  print(s or partial)
  if status == "closed" then 
    break 
  end
end
client:close()

What should i do to get the response from server ?

I want to send some info to this website and get the result of page.

Any ideas ?


Solution

  • I solved the problem passing the header

    local LuaSocket = require("socket")
    client = LuaSocket.connect("example.com", 80)
    client:send("GET /login.php?login=admin&pass=admin HTTP/1.0\r\nHost: example.com\r\n\r\n")
    while true do
      s, status, partial = client:receive('*a')
      print(s or partial)
      if status == "closed" then 
        break 
      end
    end
    client:close()