8

I searched a lot on Google as well as Stackoverflow. I could not find How to get Cookies (or in general, The HTTP Headers)from a Webpage and then edit it and send it back?

[I know how to make POST/GET requests using read/write but Cookies idk]

  • Red now has just temporary IO support that provides just basic functionality. For full IO support you should wait for 0.7.0. – rebolek Mar 23 '16 at 08:49
  • Okay... @rebolek BTW CTRL+F searching https://github.com/red/red/blob/master/runtime/simple-io.reds for `header` shows a lots of stuff. Are you sure it is not possible to extract the header yet? – Noobscripter Mar 23 '16 at 09:01
  • This was just an assumption and @docKimbel proved me wrong, it’s possible even now, which is a good thing. Anyway, my point stands that full IO functionality is 0.7.0 thing. – rebolek Mar 24 '16 at 06:48

2 Answers2

9

Even with the current temporary IO support, you can still extract HTTP headers and cookies info:

red>> data: read/info http://microsoft.com
== [200 #(
Cache-Control: "no-cache, no-store"
Connection: "keep-alive"
Date: "Wed,...

red>> list: data/2/set-cookie
== [{MS-CV=z/YnyU+5wE2gT8S1.1; domain=.microsoft.com; expires=Thu, 24-Mar-2016    10:59:39 GMT; pa...

red>> foreach str list [probe parse str [collect [keep to "=" skip keep to [";" | end]]]]
["MS-CV" "z/YnyU+5wE2gT8S1.1"]
["MS-CV" "z/YnyU+5wE2gT8S1.2"]

The HTTP headers are stored in a map!, so if several Set-Cookie headers are sent, you will get a block of strings, else just a string for the Set-Cookie key.

read/info will return a block with 3 elements:

  • HTTP return code (integer!)
  • HTTP headers (map!)
  • requested data (string! or binary!)

Notes:

  • HTTPS is supported by read and write.
  • the best place to get information about Red is to join the Red chat room on Gitter. ;-)
DocKimbel
  • 3,127
  • 16
  • 27
2

cookies are just a field in the response header

did you try "the library people"

tomc
  • 1,146
  • 6
  • 10