简体   繁体   English

如何在Rails中记录原始的HTTP请求/响应?

[英]How can I log the raw http request/response in rails?

Is there any way to log the raw http requests/responses in rails? 有什么方法可以将原始的HTTP请求/响应记录在Rails中吗?

that is, the plain text http message, including the body, even if the body is binary 即纯文本http消息,包括正文,即使正文为二进制

It depends a bit on what exactly you want to log. 这取决于要确切记录的内容。 But I believe raw_post is what you are looking for. 但是我相信raw_post是您想要的。 This will return the raw POST body. 这将返回原始POST正文。 You can call this method in any of your methods in the controller. 您可以在控制器中的任何方法中调用此方法。

A similar method exist for getting the GET params: raw_params 存在用于获取GET参数的类似方法: raw_params

If that isn't good enough then a middleware layer might help. 如果那还不够好,那么中间件层可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM