Rebol中的read
和write
命令,传递了一个URL!参数,可以得到二进制响应或错误。因此,在执行GET或POST的“一次性”风格中,无处可获得响应头。
result: read http://www.rebol.com
在这篇关于如何在Rebol2中执行此操作的帖子中,它建议你必须打开一个端口!并从端口的local / headers字段获取它:
这适用于Rebol2,例如
hp: open http://www.rebol.com
result: read hp
probe hp/locals/headers/Content-Encoding
但是在Rebol3中,当我打开一个端口并尝试这个时,端口的locals字段是空的。如何在Rebol3中实现相同的行为?
答案 0 :(得分:2)
一个(冗长的)解决方案:
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
答案 1 :(得分:2)
这是你正在寻找的吗?
>> 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"
]
]