Noobscripter
Noobscripter

Reputation: 1

|Red Programming Language| How to get Cookies from a Webpage?

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]

Upvotes: 8

Views: 945

Answers (2)

DocKimbel
DocKimbel

Reputation: 3199

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

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

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

>> 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. ;-)

Upvotes: 10

tomc
tomc

Reputation: 1207

cookies are just a field in the response header

did you try "the library people"

Upvotes: 2

Related Questions