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

ぃ、小莉子 提交于 2020-01-02 05:07:27

问题


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:


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"
  }
}


来源:https://stackoverflow.com/questions/29683904/how-do-i-pass-a-url-a-cookie-using-rebol-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!