Storing Cookie to login onto a website

aled99

New Member
Hi
I've been trying to login to a website using a POST request.
I send a request containing my username and password to the a URL used to login to the website, and I believe I'm logged in fine.

The problem comes when trying to store the cookie which is returned.
After I'm logged in the website automatically redirects me back to the homepage.

This means when I try and use response.Headers to get the cookie, I get the headers from the page it redirects me to. (I need the cookie returned from the login page)

Is there any way of stopping it from redirecting me/ storing the cookie before it redirects?

Thanks for your help
 

Pachuquin

Member
Licensed User
Longtime User
I had the same problem.

You have to send the value of AllowAutoRedirect=false in the header.

I solved with the Door library.

B4X:
bit.New1
Request.New1("http://www.megavideo.com/?s=signup")
Request.Method = "POST"
Request.ContentType = "application/x-www-form-urlencoded"
Request.Timeout = 30000
[COLOR="Blue"]obj.New1(False)
obj.FromLibrary("Main.Request","req",B4PObject(2))
obj.SetProperty("AllowAutoRedirect","false")[/COLOR]
s="action=login&cnext=&snext=&touser=&user=&nickname=" & nickname & "&password=" & password
buffer() = bit.StringToBytes(s,0,StrLength(s))
Request.ContentLength=StrLength(s)
bin.New1(Request.GetStream,True)
bin.WriteBytes(buffer())
Response.New1
Response.Value = Request.GetResponse
header=response.Headers
Response.Close
 

Pachuquin

Member
Licensed User
Longtime User
BRILLIANT!!

I'd tried using the door library and "Referer" but didn't know about "AllowAutoRedirect".

It runs Perfectly now!

Thanks for your help!

Does anyone know how we can use that cookie in a Webbrowser control?

Thanks
 
Top