I'm trying to create a script to enable the bandwidth control QOS service of my router, but I'm doing something wrong because I can not keep the connection after making a POST request.
local host = '192.168.0.1'
local headers = [[]]
local LuaSocket = require("socket")
client = LuaSocket.connect(host, 80)
headers = [[Host: 192.168.0.1
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
Username=admin&checkEn=0&Password=admin]]
client:send("POST /LoginCheck " .. headers)
print("First request")
while 1 do
r, err = client:receive()
if err then
break
end
print(r)
end
headers = [[Host: 192.168.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://192.168.0.1/index.asp
Cookie: language=pt; admin:language=pt
Connection: keep-alive]]
client:send("GET /goform/trafficForm?GO=net_tc.asp&tc_enable=1&up_Band=12800&down_Band=12800&cur_number=2&tc_list_1=80,100,100,1,50,2000,1,1&tc_list_2=80,101,150,1,1,50,1,1 HTTP/1.0" .. headers)
print("Second request")
while 1 do
r, err = client:receive()
if err then
break
end
print(r)
end
client:close()
When running, I have this
First request
HTTP/1.0 302 Redirect
Server: GoAhead-Webs
Date: Wed Aug 03 05:09:46 2016
Set-Cookie: admin:language=pt; path=/
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Location: index.asp
Second request
By the browser, I have this POST response in / LoginCheck
Cache-Control: no-cache
Content-Type: text/html
Date: Wed Aug 03 05:13:15 2016
Location: index.asp
Pragma: no-cache
Server: GoAhead-Webs
Set-Cookie: admin:language=pt; path=/
From what I saw, it logs in, but I do not know how to maintain the connection to get the GET request that would activate the bandwidth control.
NOTE: In order to get access to any page of the router, I need to log in to the 192.168.0.1/login.asp page, which makes a POST request for 192.168.0.1/LoginCheck , and if successful, redirects to 192.167.0.1/index.asp and then you can access the other pages of it.