Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Reading and setting cookies

 [1/17] from: gchillemi:aliceposta:it at: 20-Nov-2005 11:01


Hello, I need to download the messages from our company message board using rebol. After a successful login a cookie is set from the browser and I can navigate the message board. I need to read and set cookies when accessing pages. How can I do this ? I have found a "cookies-daemon.r" version 0.3.1 but it fails. Is there some good documentation and scripts ? Giuseppe Chillemi

 [2/17] from: SunandaDH:aol at: 20-Nov-2005 5:12


Giuseppe :
> I need to read and set cookies when accessing pages. How can I do this ?
Setting a cookie is as simple as printing the right HTTP header: print "set-cookie: ....." Reading the cookie means looking in a CGI header cookie-value: select system/options/cgi/other-headers "HTTP_COOKIE" [It's slightly more complicated if you want to use multiple cookies of type 2 for any one visitor.] Some sample code and (incomplete) notes on it here: http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?color=yes&script=cook ie-example.r http://www.rebol.org/cgi-bin/cgiwrap/rebol/documentation.r?script=cookie-examp le.r Sunanda.

 [3/17] from: gchillemi:aliceposta:it at: 20-Nov-2005 13:35


Ciao Sunanda, I am on the client side of the thing. I want to access pages located in a remote server and I need to accept a cookie and make a login. I am taking a look at http-tools.r but it does not set the data as promised: http-tools-data/cookie-data is empty. Giuseppe Chillemi -----Messaggio originale----- Da: rebol-bounce-rebol.com [mailto:rebol-bounce-rebol.com] Per conto di SunandaDH-aol.com Inviato: domenica 20 novembre 2005 11.13 A: rebolist-rebol.com Oggetto: [REBOL] Re: Reading and setting cookies Giuseppe :
> I need to read and set cookies when accessing pages. How can I do this
? Setting a cookie is as simple as printing the right HTTP header: print "set-cookie: ....." Reading the cookie means looking in a CGI header cookie-value: select system/options/cgi/other-headers "HTTP_COOKIE" [It's slightly more complicated if you want to use multiple cookies of type 2 for any one visitor.] Some sample code and (incomplete) notes on it here: http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?color=yes&script=co ok ie-example.r http://www.rebol.org/cgi-bin/cgiwrap/rebol/documentation.r?script=cookie-exa mp le.r Sunanda.

 [4/17] from: gabriele:colellachiara at: 20-Nov-2005 14:14


Hi Giuseppe, On Sunday, November 20, 2005, 1:35:57 PM, you wrote: GC> I am on the client side of the thing. GC> I want to access pages located in a remote server and I need to GC> accept a cookie and make a login. I am taking a look at http-tools.r but it GC> does not set the data as promised: GC> http-tools-data/cookie-data is empty. A few hints:
>> p: open http://www.rebol.com
connecting to: www.rebol.com
>> print p/locals/headers
Date: "Sun, 20 Nov 2005 13:03:58 GMT" Server: "Apache" Last-Modified: "Thu, 10/Nov/2005/23:00:37/+GMT" Accept-Ranges: "bytes" Content-Encoding: none Content-Type: "text/html" Content-Length: "8015" Location: none Expires: none Referer: none Connection: "close" Authorization: none ETag: {"1d0325-1f4f-4373d115"}
>> close p >> p: read/custom http://www.rebol.com [header [Cookie: "name=value"]]
connecting to: www.rebol.com == {<html> <head> <META NAME="Description" CONTENT="Lightweight distributed computing, collaboration, and programming systems for t... Regards, Gabriele. -- Gabriele Santilli <gabriele-rebol.com> --- http://www.rebol.com/ Colella Chiara software division --- http://www.colellachiara.com/

 [5/17] from: gchillemi::aliceposta::it at: 20-Nov-2005 15:05


Ciao Gabriele, seems good but it is really cryptic. I have some questions: 1) Which is the difference between this approach and http-tools.r approach ? 2) Read/custom and the block we could pass to it are undocumented 3) About Cookie: "name=value"; how could I pass more cookis values ? Where is some documentation about this way of operating ? Thanks Giuseppe Chillemi -----Messaggio originale----- Da: rebol-bounce-rebol.com [mailto:rebol-bounce-rebol.com] Per conto di Gabriele Santilli Inviato: domenica 20 novembre 2005 14.14 A: Giuseppe Chillemi Oggetto: [REBOL] Re: R: Re: Reading and setting cookies Hi Giuseppe, On Sunday, November 20, 2005, 1:35:57 PM, you wrote: GC> I am on the client side of the thing. GC> I want to access pages located in a remote server and I need to GC> accept a cookie and make a login. I am taking a look at http-tools.r but it GC> does not set the data as promised: GC> http-tools-data/cookie-data is empty. A few hints:
>> p: open http://www.rebol.com
connecting to: www.rebol.com
>> print p/locals/headers
Date: "Sun, 20 Nov 2005 13:03:58 GMT" Server: "Apache" Last-Modified: "Thu, 10/Nov/2005/23:00:37/+GMT" Accept-Ranges: "bytes" Content-Encoding: none Content-Type: "text/html" Content-Length: "8015" Location: none Expires: none Referer: none Connection: "close" Authorization: none ETag: {"1d0325-1f4f-4373d115"}
>> close p >> p: read/custom http://www.rebol.com [header [Cookie: "name=value"]]
connecting to: www.rebol.com == {<html> <head> <META NAME="Description" CONTENT="Lightweight distributed computing, collaboration, and programming systems for t... Regards, Gabriele. -- Gabriele Santilli <gabriele-rebol.com> --- http://www.rebol.com/ Colella Chiara software division --- http://www.colellachiara.com/

 [6/17] from: compkarori::gmail::com at: 20-Nov-2005 21:20


http-tools was written at a time when Rebol did not support cookies ( well, it only supported one cookie ). I believe it does now. The problem with http-tools is that it implements it's own http protocol rather than building upon RT's one. On 11/21/05, Giuseppe Chillemi <gchillemi-aliceposta.it> wrote:
> Ciao Gabriele, > seems good but it is really cryptic. I have some questions:
<<quoted lines omitted: 54>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Graham Chiu

 [7/17] from: gchillemi:aliceposta:it at: 21-Nov-2005 1:32


> http-tools was written at a time when Rebol did not support cookies ( > well, it only supported one cookie ). > I believe it does now.
I suppose this thanks to the reply of Greg but there is no documentation.
> The problem with http-tools is that it implements it's own http > protocol rather than building upon RT's one.
Now http-tools.r is working and I know hot to pass http post values but I would be much happier to fully understand the inner working of what greg has written to me. Giuseppe Chillemi

 [8/17] from: gchillemi::aliceposta::it at: 21-Nov-2005 1:33


> Now http-tools.r is working and I know hot to pass http post values > but I would be much happier to fully understand the inner working of what > greg has written to me.
Oooops.... The person is Gabriele and not Greg. Giuseppe Chillemi

 [9/17] from: volker::nitsch::gmail::com at: 21-Nov-2005 2:49


On 11/21/05, Giuseppe Chillemi <gchillemi-aliceposta.it> wrote:
> > > Now http-tools.r is working and I know hot to pass http post values > > but I would be much happier to fully understand the inner working of what > > greg has written to me. > > Oooops.... The person is Gabriele and not Greg. >
Based on Gabrieles code a short demo. Hope it makes some sense. Accessing cookie-pages. A very raw demo, cookie-parsing needs lots of improvements. browser-demo: http://polly.rebol.it/cgi-bin/cookie-demo.cgi cgi-source: http://polly.rebol.it/test/test/cookie-demo/cookie-demo.cgi rebol client-demo: http://polly.rebol.it/test/test/cookie-demo/cookie-demo.r
> Giuseppe Chillemi > > -- > To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject. >
-- -Volker Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem. David Wheeler

 [10/17] from: gchillemi::aliceposta::it at: 21-Nov-2005 11:26

Re: Reading and setting cookies (and HTTP POST )


> Based on Gabrieles code a short demo. Hope it makes some sense. > Accessing cookie-pages. > A very raw demo, cookie-parsing needs lots of improvements. > browser-demo: http://polly.rebol.it/cgi-bin/cookie-demo.cgi > cgi-source: http://polly.rebol.it/test/test/cookie-demo/cookie-demo.cgi > rebol client-demo:
http://polly.rebol.it/test/test/cookie-demo/cookie-demo.r Ciao Volker, The last example matches part of the output obtained using HTTP TOOLS. I need only further parsing on the values of the cookie but that's simple now. A last question remains. HTTP TOOLS does the following 1) It issues a "/ POST" command 2) Then he sends the header 3) He put the encoded data using the command: "insert http-port-private encoded-data" Here is the HTTP POST header taken from HTTP TOOLS. HTTP-Post-Header: make object! [ Accept: "text/html" User-Agent: reform ["REBOL" system/version] Host: port-spec/host Content-Type: "application/x-www-form-urlencoded" Content-Length: length? encoded-data Cookie: http-tools-data/cookie-data Authorization: join {Basic } enbase rejoin [http-tools-data/username ":" http-tools-data/password] ] The questions are: DOES open/custom issues a "/ POST" command too ? If the answer is YES: How to express the encoded data after the header ? Giuseppe Chillemi

 [11/17] from: gabriele:colellachiara at: 21-Nov-2005 12:51


Hi Giuseppe, On Monday, November 21, 2005, 11:26:32 AM, you wrote: GC> DOES open/custom issues a "/ POST" command too ? GC> If the answer is YES: How to express the encoded data after the header ? It does if you want it too. I.e.: read/custom url [post "postdata" [Cookie: "name=value"]] The header part is optional, that is you can just: read/custom url [post "postdata"] postdata is whatever your CGI app is expecting, which usually is something like "name=value&name2=value2". Regards, Gabriele. -- Gabriele Santilli <gabriele-rebol.com> --- http://www.rebol.com/ Colella Chiara software division --- http://www.colellachiara.com/

 [12/17] from: volker::nitsch::gmail::com at: 21-Nov-2005 17:40


On 11/21/05, Giuseppe Chillemi <gchillemi-aliceposta.it> wrote:
> > Based on Gabrieles code a short demo. Hope it makes some sense. > > Accessing cookie-pages.
<<quoted lines omitted: 6>>
> The last example matches part of the output obtained using HTTP > TOOLS.
That was the point. Its inbuild now, no http-tools needed ;) I
> I need only further parsing on the values of the cookie but that's > simple now.
[snip]

 [13/17] from: gchillemi:aliceposta:it at: 21-Nov-2005 20:07


>> Ciao Volker, >> The last example matches part of the output obtained >> using HTTP TOOLS. > That was the point. Its inbuild now, no http-tools needed ;)
WOW, it is one of the best kept secrets. It is written nowhere in the official documentations ! Tonight or tomorrow I'll try to download a web page providing cookies and posting values. Giuseppe Chillemi

 [14/17] from: compkarori::gmail::com at: 21-Nov-2005 21:51


Probably true, but those of us who were following/involved in the 1.3 collaboration knew about the improvements to the http scheme, and so read about the doc changes which were on-going in the release notes. On 11/22/05, Giuseppe Chillemi <gchillemi-aliceposta.it> wrote:
> >> Ciao Volker, > >> The last example matches part of the output obtained
<<quoted lines omitted: 5>>
> posting values. > Giuseppe Chillemi
-- Graham Chiu

 [15/17] from: antonr::lexicon::net at: 22-Nov-2005 11:45


Added a discussion post to http-tools.r in rebol.org (well done Sunanda, all working smoothly). I just said the functionality is built in to rebol now, and gave Gabriele's examples below. Perhaps Graham, the owner of http-tools.r, can put a note saying that the script is now (partly?) obsolete. (I also suggest to put the Purpose above the Usage, while you're at it..) Anton.

 [16/17] from: rebol-list2:seznam:cz at: 27-Nov-2005 15:52

Re: Reading and setting cookies


Hello Giuseppe, Sunday, November 20, 2005, 11:01:30 AM, you wrote: GC> Hello, GC> I need to download the messages from our company message board using GC> rebol. After a successful login a cookie is set from the browser and I can GC> navigate the message board. GC> I need to read and set cookies when accessing pages. How can I do this ? GC> I have found a "cookies-daemon.r" version 0.3.1 but it fails. Is there some GC> good documentation and scripts ? More up to date cookies-daemon.r script is here: do http://box.lebeda.ws/~hmm/rebol/cookies-daemon_1.0.0.r Should bew working, I'm using it. If you will have problems, let me know. oldes GC> Giuseppe Chillemi -- Best regards, rebOldes -----------------[ http://oldes.multimedia.cz/ ]

 [17/17] from: rebol-list2:seznam:cz at: 27-Nov-2005 16:06


Hello Volker, Monday, November 21, 2005, 2:49:15 AM, you wrote: VN> On 11/21/05, Giuseppe Chillemi <gchillemi-aliceposta.it> wrote:
>> >>
<<quoted lines omitted: 4>>
>> Oooops.... The person is Gabriele and not Greg. >>
VN> Based on Gabrieles code a short demo. Hope it makes some sense. VN> Accessing cookie-pages. VN> A very raw demo, cookie-parsing needs lots of improvements. VN> browser-demo: http://polly.rebol.it/cgi-bin/cookie-demo.cgi VN> cgi-source: http://polly.rebol.it/test/test/cookie-demo/cookie-demo.cgi VN> rebol client-demo: http://polly.rebol.it/test/test/cookie-demo/cookie-demo.VN> r The expires date format used in the cookies-demo.cgi is not correct. It should be formated: Wdy, DD-Mon-YYYY HH:MM:SS GMT you have: Wdy, DD Mon YYYY HH:MM:SS GMT see: http://wp.netscape.com/newsref/std/cookie_spec.html This is based on RFC 822, RFC 850, RFC 1036, and RFC 1123, with the variations that the only legal time zone is GMT and the separators between the elements of the date must be dashes.
>> >> Giuseppe Chillemi
<<quoted lines omitted: 6>>
>> >>
VN> -- VN> -Volker VN> "Any problem in computer science can be solved with another layer of VN> indirection. But that usually will create another problem." David VN> Wheeler -- Best regards, rebOldes -----------------[ http://oldes.multimedia.cz/ ]

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted