Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 976
Noobscripter Avatar asked Mar 19 '16 11:03

Noobscripter


2 Answers

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. ;-)
like image 129
DocKimbel Avatar answered Nov 20 '22 22:11

DocKimbel


cookies are just a field in the response header

did you try "the library people"

like image 40
tomc Avatar answered Nov 20 '22 21:11

tomc