Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a URL a cookie using Rebol 3?

Tags:

rebol

rebol3

Using R3, I need to get a localized version of a page from a website that uses cookies to handle this. In REBOL 2.x, I could do this:

page: http://www.rci.com/resort-directory/resortDetails?resortCode=0450         
read/custom page [header [Cookie: "USER_LOCALE=fr_FR"]]

Based on the sketchy docs for R3, I should be able to do something like:

result: write page [GET [Cookie: "USER_LOCALE"] {fr_FR}]

Anyone have any ideas? The R2 method worked well, but since R2 doesn't handle UTF-8 needed for many foreign languages it's of little use to me here.

** Update **

The solution (restated) in R2 for my example is:

  1. Assemble the required parameters in the cookie:

    cookie-str: "USER_LOCALE=fr_FR; USER_COUNTRY=US"
    
  2. Then inject the cookie into the header

    page-code: read/custom page reduce compose/deep ['header [Cookie: (cookie-str)]]
    

The solution for my example in R3 is:

page-code: to-string write page reduce compose/deep ['GET [Cookie: (cookie-str)]]
like image 589
Edoc Avatar asked Apr 16 '15 19:04

Edoc


1 Answers

Your try is almost there. You use WRITE with a small "HTTP dialect" in an argument block whenever you need to configure something about the HTTP request being sent. First item of that dialect is the HTTP method to use, second item (if present) is a block of HTTP headers to send along.

If I understand your example correctly, you want to send a cookie with "USER_LOCALE=fr_FR" as payload. So you'd do:

write page [GET [Cookie: {USER_LOCALE=fr_FR}]]

Let's test this against a httpbin:

>> print to-string write http://httpbin.org/headers [GET [Cookie: "USER_LOCALE=fr_FR"]]     
{
  "headers": {
    "Accept": "*/*", 
    "Accept-Charset": "utf-8", 
    "Cookie": "USER_LOCALE=fr_FR", 
    "Host": "httpbin.org", 
    "User-Agent": "REBOL"
  }
}
like image 137
earl Avatar answered Nov 04 '22 08:11

earl