使用http-client call-with-with-input-request时,如何获取响应对象?

发布于 2025-02-13 20:49:45 字数 674 浏览 1 评论 0原文

当http status在> = 300时,如何从call-with-input-request获取响应对象?

docs 关于call> call> call> call with-with-input--请求

返回三个值:呼叫对读者的结果(或#F响应中没有消息主体),最后一个请求的请求-URI和响应对象。如果响应代码不在200类中,则根据响应代码,它将提出类型(EXN HTTP client-error),(EXN HTTP Server-Error)或(EXN HTTP意外服务响应),具体取决于响应代码。这包括未找到404(这是客户端)。

这意味着call-with-input-request向不可触发条件发出信号,据我所知,这意味着该函数不会返回,我无法访问该函数否则将退还。因此,我看不出如何真正访问与此请求相对应的响应对象。

我仍然希望能够检查响应,即使其状态在30x-50x范围内。例如,我希望能够打印HTTP原因字符串,或将其记录为以后进行调试。我该如何实现?

How do I get the response object from call-with-input-request when the HTTP status is >= 300?

The docs say this about call-with-input-request:

Returns three values: The result of the call to reader (or #f if there is no message body in the response), the request-uri of the last request and the response object. If the response code is not in the 200 class, it will raise a condition of type (exn http client-error), (exn http server-error) or (exn http unexpected-server-response), depending on the response code. This includes 404 not found (which is a client-error).

This means that call-with-input-request signals a non-continuable condition, which (as far as I understand) means that the function does not return, and I cannot get access to the response object that would otherwise be returned. Therefore I don't see how I can actually get access to the response object corresponding to this request.

I still want to be able to inspect the response, even if its status is in the 30x-50x range. For example, I want to be able to print the HTTP reason string, or log it for debugging later. How can I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滴情不沾 2025-02-20 20:49:45

如果触发复制的异常,则可以使用,exn comma-command进行检查。然后,您会注意到条件具有响应属性,该属性包含状态代码,标题等。

我敢肯定,在这方面可以改进文档。也许您有一个建议将其放在哪里?问题在于,条件对象的确切内容取决于条件的抛弃位置,因此并非所有属性都将始终可用。

If you trigger the exception from the REPL, you can inspect it with the ,exn comma-command. Then you'll notice the condition has a response property which is a contains the status code, headers etc.

The docs could be improved in this regard I'm sure. Perhaps you have a suggestion where to put this? The problem is that the exact contents of the condition object depend on where the condition was thrown, so not all properties will always be available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文