如何使用Rebol 3将URL传递给cookie? [英] How do I pass a URL a cookie using Rebol 3?

查看:100
本文介绍了如何使用Rebol 3将URL传递给cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用R3,我需要从使用Cookie进行处理的网站上获取页面的本地化版本.在REBOL 2.x中,我可以这样做:

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

基于R3的粗略文档,我应该能够执行某些操作,例如:

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

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

有人有什么想法吗? R2方法效果很好,但是由于R2无法处理许多外语所需的UTF-8,因此在这里对我没有多大用处.

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.

** 更新 **

在我的示例中,R2中的解决方案(重述)为:

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

  1. 在cookie中组装所需的参数:

  1. Assemble the required parameters in the cookie:

cookie-str: "USER_LOCALE=fr_FR; USER_COUNTRY=US"

  • 然后将cookie注入标题中

  • Then inject the cookie into the header

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

  • 我在R3中的示例的解决方案是:

    The solution for my example in R3 is:

    page-code: to-string write page reduce compose/deep ['GET [Cookie: (cookie-str)]]
    

    推荐答案

    您的尝试在那里几乎.每当需要配置有关正在发送的HTTP请求的内容时,都可以在参数块中使用带有小"HTTP方言"的WRITE.该方言的第一项是要使用的HTTP方法,第二项(如果存在)是要发送的HTTP标头块.

    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.

    如果我正确理解了您的示例,则希望发送一个以"USER_LOCALE = fr_FR"作为有效载荷的cookie.所以你会做:

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

    让我们针对 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"
      }
    }
    

    这篇关于如何使用Rebol 3将URL传递给cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆