How to get the response content of an HTTP 404 response

若如初见. 提交于 2019-12-04 09:47:22

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.

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]
]

The caveat here is that the HTTP protocol has to have been initiated (any http port opened/read). response-actions can still be accessed when http has not been initiated:

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]

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.

Christopher Ross-Gill has created a REST protocol for Rebol which allows simple access to all headers and even handles OAuth. Have a look at the details here.

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

Unfortunately it is only for Rebol 2 at the moment and it depends on the use of curl for the http requests.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!