Keep connection active after a POST request

Asked

Viewed 163 times

1

I am trying to create a script to activate the QOS bandwidth control service of my router, but I am doing something wrong because I can’t 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 performing, 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

Through the browser, I have this answer from POST 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, he logs in, but I don’t know how to maintain the connection to get the GET order that would activate the bandwidth control.

NOTE: To access any page of the router, I need to login to the page 192.168.0.1/login.Asp, who makes a POST request to 192.168.0.1/Logincheck, and if successfully performed, redirect to 192.167.0.1/index.Asp and then you can access the other pages of the same.

1 answer

1


To save the data, it is necessary to go up a session, for the server to save the data in the user session, the header sent to the server must contain the session data.

Cookie: csrftoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

This causes the server to save user session data until it closes the browser and switches session.

GET / HTTP/1.1
Host: localhost:8081
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pt-BR
Accept-Encoding: gzip, deflate
DNT: 1
Cookie: csrftoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Connection: keep-alive
Upgrade-Insecure-Requests: 1

This header is from the browser request Firefox, the property Cookie present in the header, is responsible for saving the user’s session data, having the variable csrftoken who owns the id user session.

In some cases the csrftoken, is not the only value for the session, having also the sessionid with the same format.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.