如何获取HTTP 404响应的响应内容 [英] How to get the response content of an HTTP 404 response

查看:372
本文介绍了如何获取HTTP 404响应的响应内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there an easier way of getting the content of an HTTP 404 response than directly accessing the host via tcp?

这是包含内容的404响应的示例:

This is a sample of a 404 response with content:

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


推荐答案

Rebol HTTP方案真的不是用这个设计的记住,它的目的是按照你在浏览器中的方式阅读内容,而不是通过HTTP服务。

The Rebol HTTP scheme really isn't designed with this in mind, it's geared toward reading content the way you would in a browser, not services over HTTP.

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

In saying that, you can hack the protocol to subvert how Rebol 2 handles different response codes:

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

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

您可以获取最后一个响应行因此:

You can get the last response line thus:

in-http-scheme [response-line]

或者你需要一个专为HTTP服务设计的方案。我有一个 REST协议(两个版本,一个使用cURL ,并使用定制的HTTP方案有效,但效果不佳。虽然适用于Rebol 2.我计划使用Rebol 3版本。

Alternatively you are going to need a scheme designed for services over HTTP. I have a REST protocol (two versions, one that uses cURL, and one that uses a customised HTTP scheme that works, but isn't as good). Though are for Rebol 2. I have plans for a Rebol 3 version.

这篇关于如何获取HTTP 404响应的响应内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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