如何获取HTTP 404响应的响应内容

时间:2013-07-24 08:47:53

标签: http rest http-status-code-404 rebol

获取HTTP 404响应的内容是否比通过tcp直接访问主机更简单?

这是404响应的示例,内容为:

HTTP/1.1 404 Object Not Found
Server: CouchDB/1.3.0 (Erlang OTP/R15B03)
Date: Wed, 24 Jul 2013 08:32:50 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 41
Cache-Control: must-revalidate

{"error":"not_found","reason":"missing"}

2 个答案:

答案 0 :(得分:3)

Rebol HTTP方案在设计时并没有考虑到这一点,它旨在以在浏览器中的方式阅读内容,而不是通过HTTP提供服务。

在说,你可以破解协议来颠覆Rebol 2如何处理不同的响应代码:

in-http-scheme: func [does [block!]][
    do bind :does bind? last body-of get in system/schemes/http/handler 'open
]

in-http-scheme [
    remove-each [code response] response-actions [find [400 403 404] code]
    append response-actions [400 success 403 success 404 success]
]

这里需要注意的是HTTP协议必须已经启动(任何http端口打开/读取)。 response-actions 仍然可以在http尚未启动时访问:

select body-of get in system/schemes/http/handler 'open quote response-actions:

您可以获得最后一个响应行:

in-http-scheme [response-line]

或者,您将需要一个针对HTTP服务的方案。我有一个REST protocol(两个版本,一个uses cURL,另一个使用customised HTTP scheme,但效果不佳。虽然适用于Rebol 2.我计划使用Rebol 3版本。

答案 1 :(得分:0)

Christopher Ross-Gill为Rebol创建了一个REST协议,允许简单访问所有标头甚至处理OAuth。看看这里的细节。

http://www.ross-gill.com/page/REST_Protocol

不幸的是,它目前只适用于Rebol 2,它取决于对http请求使用curl。

相关问题