GET URL with cookies
lists at mangomultimedia.com
Thu Jul 10 10:46:57 EDT 2008
On Jul 10, 2008, at 10:10 AM, Bert Shuler wrote:
> I have a site which I need to authenticate to. I do this:
> put URL "http://site.com/login?uid="&URLEncode("bert at site.com") &
> "&password=" & URLEncode("mypass") into field "html"
> The host site validates my password, sets a cookie, and redirects me
> to the front page, which because I have a validated cookie, shows me
> I am logged in. This works fine in a browser, but it seem "put URL"
> is doing the redirect, but dropping the cookie. So I never actually
> get logged in.
> My question is this, can I make "put URL" keep the cookies? Or, as
> an alternate solution, can I make the revBrowser upload files with
> zero user intervention?
> Any pointers will be appreciated.
I think you have to handle cookies manually. I just did some work with
cookies yesterday so here are some notes based on that experience.
I'm using 'post' rather than 'put' but after executing the 'post'
command I used libURLLastRHHeaders() to retrieve the header that the
server sent back. You will find at least one line that starts with
What you are responsible for doing is extracting the cookie from that
line and creating a 'Cookie' entry in the header you send to the
server with each request. I put together a handler that takes
libURLLastRHHeaders(), extracts the cookies and stores them in a
script local variable (this code is for a library, you could easily
return the result) that I then assign to 'the httpheaders' property
before I send a request to the server expecting the cookie. Here is
what it looks like:
## Parse header returned from a server and create a cookie header that
can be sent back: Cookie: cookie1;cookie2;cookie3;...
private command _StoreCookies pHeader
put empty into sCookieHeader
put 0 into theOffset
put lineoffset("Set-Cookie:", pHeader, theOffset) into
if theLineNo > 0 then
add theOffset to theLineNo
put line theLineNo of pHeader into theCookieLine
delete word 1 of theCookieLine ## Set-Cookie:
put offset(";", theCookieLine) into theCharNo
if theCharNo > 0 then
delete char theCharNo to -1 of theCookieLine
put theCookieLine & ";" after sCookieHeader
put theLineNo into theOffset
if the last char of sCookieHeader is ";" then
delete the last char of sCookieHeader
if sCookieHeader is not empty then
put "Cookie: " before sCookieHeader
Hopefully this helps.
Blue Mango Learning Systems
Developer Resources: http://revolution.bluemangolearning.com
More information about the Use-livecode