雷博尔能做到吗?

发布于 2024-11-03 14:27:06 字数 896 浏览 4 评论 0原文

我正在尝试在 Rebol 中重写 C# 应用程序,以直观地了解可实现的生产力水平。

在我开始之前,我很好奇是否:

  • 解析函数可以做 Regex 可以做的所有事情

  • 可以模仿 HTTP(实际上, HTTPS)使用端口的会话!
    (这里的任何示例都很好,因为我似乎找不到任何示例)

  • 有任何方言可用于解析平面文件
    (包括 CSV、TSV、固定长度文件)

  • 有从 HTML 文件生成 PDF 的功能
    (或者只是填充现有的 PDF 表单)

谢谢!

编辑:

关于问题#2,请允许我重新表述一下,我实际上希望能够在 HTTP 请求之间维护 cookie(实际上,一个 POST [将凭据发布到登录页面],然后是许多 GET重新发送 POST 后收到的 cookie)。

我想使用curl的等价物是:

curl [url] -d [data] -c [file] 
curl [url] -b [file]

我想我的问题是我还不知道如何充分使用HTTP方案(阅读http://www.rebol.net/docs/prot-http.html) 当我执行此操作时,我在成功发布后看到一个 cookie:

p: open http://localhost/test.php
write p "name=foo"
probe p/state/info/headers

但是接下来怎么办?如何随下一个请求重新发送此 cookie。

I'm attemtping to rewrite a C# application in Rebol to see first hand the levels of productity achievable.

I was curious to know before I jump in head first whether:

  • The parse function can do everything that Regex can

  • It's possible to mimic an HTTP (actually, HTTPS) session using port!
    (Any examples here would be nice as I can't seem to find any)

  • There are any dialects available for parsing flat files
    (including CSV, TSV, fixed length files)

  • There are functions to generate a PDF from an HTML file
    (or just populate an existing PDF form)

Thanks!

EDIT:

On question #2, allow me to rephrase, I actually want to be able to maintain cookies between HTTP requests (actually, a POST [posting credentials to a login page], followed by numerous GETs that resend the cookie received after POSTing).

I guess the equivalent using curl would be:

curl [url] -d [data] -c [file] 
curl [url] -b [file]

I guess my problem is I just don't know yet how to fully use the HTTP scheme (reading http://www.rebol.net/docs/prot-http.html) I see a cookie after a successfull post when I do this:

p: open http://localhost/test.php
write p "name=foo"
probe p/state/info/headers

But then what next? How do I resend this cookie along with the next request.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2024-11-10 14:27:06

解析函数可以完成 RegEx 可以做的所有事情吗?

Rebol 的 PARSE 属于“自顶向下解析语言 (TDPL)”家族。它应该比 RegEx 或 LL 解析器更强大。有关可能/不可能的详细信息,请参阅我对问题的回答 “你能在Rebol中为CSS2/CSS3创建解析规则吗”(A:是)

是否可以模仿HTTP (实际上,HTTPS)会话使用端口!

您可以在 Rebol 中编写完整的 Web 服务器 - 正如 Cheyenne 所演示的......并且您可以 在线浏览其源代码。如果您想要一个更简单的示例,请查看小型 Web 服务器示例

关于通过 cookie 进行的“会话管理”的具体问题,并没有很好的记录如何为了做到这一点......无论好坏,我都不使用 Rebol 2。我的看法是,这是您必须感受版本之间变化的领域之一。

FWIW,这段代码在我在 Rebol 3 中编写的一个使用 cookie 的小脚本中为我工作:

    system/schemes/http/spec/headers: compose [
        cookie: (session_cookie)
        referer: (to-string urlForEdit)
        content-type: {application/x-www-form-urlencoded}
        user-agent: {Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3}
        cache-control: {no-cache}
    ]

    either true [
        system/schemes/http/spec/method: 'post
        system/schemes/http/spec/content: payloadString
        htmlResponse: to-string read postUrl
    ] [
        # this seems to be equivalent to the other branch... 
        # if the target of your WRITE is of type URL! then it
        # automatically sets spec/method and http/spec/content

        htmlResponse: to-string write postUrl payloadString
    ]

是否有可用于解析平面文件的方言?

除了 PARSE 之外,我不知道有任何已发布的方言,通常用于 将 CSV 等内容导入 Rebol格式。然后程序以 Rebol 的形式对数据进行操作。一件不幸的事情是 PARSE 不在 PORT 上运行! 因此,如果您的文件很大,您可能必须实现自己的缓冲解决方案。

是否有从 HTML 文件生成 PDF 的函数?

从 HTML 生成 PDF 或填写表单听起来像是一种交钥匙工程,您可能需要调用外部维护的工具来实现。但是 Gabriele Santilli 有一个项目可以从 Rebol PDF 方言生成合法的 PDF 文件:

http://web.tiscalinet.it/rebol/pdf-maker.r

有趣的是该库的文档是一个使用库本身制作的 PDF 文件。如果您想查看用于创建它的方言代码,您可以将它与生成的结果并排查看!

http://web.tiscalinet.it/rebol/pdf-maker-doc。

Can the parse function do everything that RegEx can?

Rebol's PARSE is in the family of "Top-down parsing languages (TDPL)". It should be strictly more powerful than RegEx or LL parsers. For a breakdown of what's possible/impossible see my answer to the question "Can you create PARSE rules for CSS2/CSS3 in Rebol" (A: Yes)

Is it possible to mimic an HTTP (actually, HTTPS) session using port!

You can write full web servers in Rebol--as demonstrated by Cheyenne...and you can browse its source code online. If you want a far simpler example check out the Tiny Web Server Sample.

With respect to the specific issue of "session management" via cookies, it's not terribly well documented how to do this...and for better or worse I do not use Rebol 2. My perception is that this is one of the areas where you'll have to feel out changes between versions.

FWIW, this code was working for me in a little script I wrote in Rebol 3 that used cookies:

    system/schemes/http/spec/headers: compose [
        cookie: (session_cookie)
        referer: (to-string urlForEdit)
        content-type: {application/x-www-form-urlencoded}
        user-agent: {Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3}
        cache-control: {no-cache}
    ]

    either true [
        system/schemes/http/spec/method: 'post
        system/schemes/http/spec/content: payloadString
        htmlResponse: to-string read postUrl
    ] [
        # this seems to be equivalent to the other branch... 
        # if the target of your WRITE is of type URL! then it
        # automatically sets spec/method and http/spec/content

        htmlResponse: to-string write postUrl payloadString
    ]

Are there dialects available for parsing flat files?

I'm not aware of any published dialects other than PARSE, which is typically used to get things like CSV into Rebol formats. Then the program operates on the data as Rebol. One unfortunate thing is that PARSE doesn't run on PORT! so if your file is large you may have to implement your own buffering solution.

Are there functions to generate a PDF from an HTML file?

Generating a PDF from HTML or filling out forms sounds like kind of a turnkey thing that you might want to call to an externally maintained tool for. But there is a project out there by Gabriele Santilli which generates legal PDF files from a Rebol PDF dialect:

http://web.tiscalinet.it/rebol/pdf-maker.r

What's fun is the documentation for the library is a PDF file which was made using the library itself. If you want to see the dialected code used to create it, you can look at it side-by-side with the generated result!

http://web.tiscalinet.it/rebol/pdf-maker-doc.r

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文