首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Rebol3中获取HTTP响应头?

如何在Rebol3中获取HTTP响应头?
EN

Stack Overflow用户
提问于 2014-01-20 04:54:42
回答 2查看 200关注 0票数 2

当传递URL时,Rebol中的readwrite命令!参数,可以获得二进制响应或错误。因此,在做GET或POST的“一次性”风格中,没有地方可以从其中获取响应头。

代码语言:javascript
复制
result: read http://www.rebol.com

在这篇关于如何在Rebol2中进行操作的文章中,它建议您必须打开一个端口!并从端口的本地/标头字段获取它:

Rebol - HTTP response headers

例如,这在Rebol2中起作用。

代码语言:javascript
复制
hp: open http://www.rebol.com
result: read hp
probe hp/locals/headers/Content-Encoding

但是在Rebol3中,当我打开一个端口并尝试这一点时,端口的局部变量字段是空的。如何在Rebol3中实现相同的行为?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-05 08:21:45

这就是你要找的吗?

代码语言:javascript
复制
>> hp: open http://www.rebol.com/
>> to string! read hp
== {<!doctype html>
<html><head>
<meta name="generator" content="REBOL WIP Wiki"/>
<meta name="date" content="16-Feb-2014/15:58:59-8:00"/>
<meta name="rebol-version" content="2.100.97.4.2"/>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta name="Description" content="REBOL: a lightweight computer language with ad
vanced semantics. ...

>> query hp
== make object! [
    name: %/
    size: 7118
    date: none
    type: 'file
    response-line: "HTTP/1.1 200 OK"
    response-parsed: 'ok
    headers: make object! [
        Content-Length: 7118
        Transfer-Encoding: none
        Last-Modified: "Sun, 16 Feb 2014 23:58:59 GMT"
        Date: "Sat, 05 Apr 2014 08:19:34 GMT"
        Server: "Apache"
        Accept-Ranges: "bytes"
        Connection: "close"
        Content-Type: "text/html"
    ]
]
票数 2
EN

Stack Overflow用户

发布于 2014-01-20 05:01:46

一种(长卷)解决方案:

代码语言:javascript
复制
target: http://www.rebol.com/
port: make port! target
; make alterations to port/spec here, e.g.
; port/spec/method -- HTTP method
; port/spec/headers -- [set-word value] block of headers
; port/spec/content -- content
port/awake: func [event][
    switch event/type [
        connect [read event/port false]
        done [true]
    ]
]
open port
response: query port
wait [port 1]
close port
probe response
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21226498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档