gpt4 book ai didi

ruby-on-rails - 在 Rails 中,如何记录每个传入 HTTP 请求的全部内容?

转载 作者:行者123 更新时间:2023-12-04 07:02:04 24 4
gpt4 key购买 nike

我正在构建一个与 Rails 后端通信的应用程序,该后端向 Rails 发送请求。它失败了。有没有一种简单的方法可以让 Rails 记录和吐出来控制每个传入的 HTTP 请求的整体?

如果有人感到特别慈善,您也许可以帮助解决根本原因。使用简单的 curl 命令可以正常工作:

$ curl -X POST -d "<person><name>Jack</name></person>" -H "Content-Type: application/xml" http://localhost:3000/people.xml
<?xml version="1.0" encoding="UTF-8"?>
<person>
<created-at type="datetime">2009-11-08T16:36:54Z</created-at>
<id type="integer">3</id>
<name>Jack</name>
<updated-at type="datetime">2009-11-08T16:36:54Z</updated-at>
</person>

但是当我的应用程序发送请求时 Rails 吐出的错误是:

/!\ FAILSAFE /!\ Sun Nov 08 11:38:23 -0500 2009 Status: 500 Internal Server Error bad content body /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/utils.rb:347:in `parse_multipart' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/utils.rb:319:in `loop' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/utils.rb:319:in `parse_multipart' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/request.rb:141:in `POST' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/methodoverride.rb:15:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/params_parser.rb:15:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/session/cookie_store.rb:93:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/failsafe.rb:26:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `synchronize' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/lock.rb:11:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/dispatcher.rb:114:in `call' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/reloader.rb:34:in `run' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/dispatcher.rb:108:in `call' /Library/Ruby/Gems/1.8/gems/rails-2.3.4/lib/rails/rack/static.rb:31:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:46:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in `each' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/urlmap.rb:40:in `call' /Library/Ruby/Gems/1.8/gems/rails-2.3.4/lib/rails/rack/log_tailer.rb:17:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/content_length.rb:13:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/chunked.rb:15:in `call' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:61:in `process' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run' /Library/Ruby/Gems/1.8/gems/rack-1.0.0/lib/rack/handler/mongrel.rb:34:in `run' /Library/Ruby/Gems/1.8/gems/rails-2.3.4/lib/commands/server.rb:111 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' script/server:3

最佳答案

您最好的选择可能是让前端服务器(apache、nginx 等)吐出这些...

或者,如果您想从 rails 中执行此操作,请使用 request.env在 Controller 中,例如如下

logger.info(request.env.inspect)

关于ruby-on-rails - 在 Rails 中,如何记录每个传入 HTTP 请求的全部内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1697104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com