| Red programming language | How to get cookies from a web page?

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

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

+5
source share
2 answers

Even with current temporary IO support, you can still retrieve HTTP headers and cookies:

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"] 

HTTP headers are stored on the card !, so if multiple Set-Cookie headers are sent, you will get a block of strings, otherwise just a string for the Set-Cookie key.

read/info will return a block with three 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 chat chat on Gitter .; -)
+7
source

cookie is just a field in the response header

You tried "library users"

0
source

Source: https://habr.com/ru/post/1245379/


All Articles