简体   繁体   English

错误:仅允许获取请求

[英]error :Only get requests are allowed

i get this exception 我得到这个例外

ActionController::MethodNotAllowed: Only get requests are allowed. ActionController :: MethodNotAllowed:仅允许get请求。

please can any one give solution for this 请任何人为此提供解决方案

This error means you are trying to post/put/delete to a path that only accepts GET requests. 此错误表示您正试图将其发布/放置/删除到仅接受GET请求的路径。 You need to confirm that your route and the path and/or form method you are using match up. 您需要确认您的路线以及所使用的路径和/或表单方法是否匹配。

This error occurs when you have defined a standard route and a client is trying to connect to the route using a HTTP method different than GET or POST. 当您定义了标准路由并且客户端尝试使用不同于GET或POST的HTTP方法连接到该路由时,会发生此错误。

Usually, this is caused by clients using the Microsoft Office Protocol Discovery. 通常,这是由使用Microsoft Office Protocol Discovery的客户端引起的。 These clients send an OPTION request which is not supported by Rails. 这些客户端发送一个OPTION请求 ,Rails不支持该请求

You can fix the problem in multiple ways: 您可以通过多种方式解决问题:

  1. ignore the error in your production environment 忽略生产环境中的错误
  2. prevent the error using a before_filter and head 406 in your controller 在控制器中使用before_filter和head 406防止错误
  3. rescue the error using rescue_from in your controller 使用控制器中的rescue_from来挽救错误
  4. prevent the error filtering the request via Rack Middleware 防止错误通过机架中间件过滤请求
  5. prevent the error blocking non GET/POST/HEAD requests using your webserver 防止使用您的网络服务器阻止非GET / POST / HEAD请求的错误

I personally prefer the last option, but it requires you to have administration privileges on the server. 我个人更喜欢最后一个选项,但是它要求您在服务器上具有管理特权。 Otherwise, the Rack Middleware option is the most efficient way to filter unexpected requests. 否则,“机架中间件”选项是过滤意外请求的最有效方法。

How are you trying to get to this page? 您如何尝试进入此页面? It looks like you are trying to do some other kind of RESTful call (put, post, delete) and that method. 看来您正在尝试进行其他类型的RESTful调用(放置,发布,删除)和该方法。 A code snipped of that controller would be really helpful to diagnose the problem. 删除该控制器的代码对诊断问题确实很有帮助。

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

相关问题 使用:symbol的form_for不起作用,错误[仅允许获取,放置和删除请求] - form_for using :symbol not working, error [Only get, put, and delete requests are allowed] ActionController :: MethodNotAllowed(仅允许获取和发布请求。): - ActionController::MethodNotAllowed (Only get and post requests are allowed.): ActionController :: MethodNotAllowed(仅允许获取,放置和删除请求。) - ActionController::MethodNotAllowed (Only get, put, and delete requests are allowed.) 如何处理或防止Ruby on Rails中的“仅允许发布请求”错误? - How to handle or prevent “Only post requests are allowed” error in Ruby on Rails? link_to无法正常工作并找不到页面仅允许get和post请求 - link_to not working and getting Page not found Only get and post requests are allowed Ruby on Rails:仅允许获取,放置和删除 - Ruby on Rails: only get, put, and delete allowed Rails仅路由link_to仅生成get请求rails 5 - Rails Routes only link_to only generating get requests rails 5 Cors的POST,PUT和PATCH请求不起作用。 只有GET - Cors Requests for POST and PUT and PATCH and so on are not working. Only GET 应用程序控制器中的before_filter仅用于获取请求 - before_filter in application controller for only get requests rails test仅在get请求中传递CSRF令牌 - rails test passing CSRF token only in get requests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM