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:
Assemble the required parameters in the cookie:
cookie-str: "USER_LOCALE=fr_FR; USER_COUNTRY=US"
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)]]
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"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With