Page 1 of 1
[Q] Problem with post form to URL and keep connected
Posted: Sat Aug 10, 2013 5:26 pm
by infantilo
Hi,
i need to login to a wegpage by posting an form, after that i should be able to get other webpage from the server, but sadly it seams as if each time using
opens a new connection.
How can i ceep the connection for further calls???
thanks for advice
Re: [Q] Problem with post form to URL and keep connected
Posted: Sat Aug 10, 2013 5:34 pm
by FourthWorld
HTTP is generally considered a stateless protocol, so the socket is closed once the transfer has been successfully completed. What is your goal with keeping the socket open? Perhaps there's another way to meet that need.
Re: [Q] Problem with post form to URL and keep connected
Posted: Sat Aug 10, 2013 5:44 pm
by infantilo
thanks for quick reply,
in b4a i had to do it this way:
Code: Select all
Dim myHttpRequest As HttpRequest
url = "https://yourURLhere.html"
Dim str() As Byte
Dim form As String
form = "usernme=max&Country=Vienna&Telephone=123456"
myhttprequest.InitializePost2(url,str)
myHttpRequest.Timeout = 5000
If sock.Execute(myHttpRequest,1) = False Then
'Something went wrong
Return
End If
then , for every request, i had to use the same socket.
can i do the same with lc.
the server connection is https.
i've tried to use a socket, but have no idea how to connetc to https using open socket. Always getting not a valid port
Re: [Q] Problem with post form to URL and keep connected
Posted: Sat Aug 10, 2013 6:13 pm
by FourthWorld
My (admittedly limited) understanding from the RFC is that HTTP 1.1 can support persistent connections with the addition of a connection-token element in the header. I'm certainly no BASIC4Android expert, but I'm not seeing where the header is modified at all - does B4A do that by default?
It may be possible to use the libUrlSetCustomHttpHeaders command to do what you need, but I've not needed persistent connections myself so beyond that we'd have to rely on the experience of someone else here who may have done this.
I'm still curious, though: what is the goal with this? Do you have concerns about server load? What's on the back side handling the request?
Re: [Q] Problem with post form to URL and keep connected
Posted: Sun Aug 11, 2013 10:05 am
by infantilo
i'm getting my workorder from an webserver. to that, i first need to load the main page, grab an token, send an form (method post) to an other page and grab the maintoken from the repled html page. then i can call the page i really want, by including the maintoken. I've done this in realbasic and b4a.
i'm goona check the libUrlSetCustomHttpHeaders command and will give report. MANY thanks.
Re: [Q] Problem with post form to URL and keep connected
Posted: Tue Aug 13, 2013 6:39 am
by infantilo
MANY thanks.... works like charm!!!!
Re: [Q] Problem with post form to URL and keep connected
Posted: Tue Aug 13, 2013 7:32 am
by FourthWorld
Glad that worked out. In case anyone here needs to do that, what specific changes did you make to the headers?