5

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

1 Answer 1

6

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"
  }
}
1
  • Thank you for the tips. Initially your code wouldn't work for me. This is because another cookie is required, one which contains geo-location. A working example of the code is: page-code: to-string write page [GET [Cookie: "USER_LOCALE=fr_FR; USER_COUNTRY=US"]]
    – Edoc
    Apr 17, 2015 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.