rebolrebol3rebol2red-lang

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


Solution

  • 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:

    Notes: