如何重定向到并返回 200 状态代码 [英] how to redirect_to and return a 200 status code
问题描述
我有一个 rails 应用程序,当用户填写表单时,它会用新的信用卡 ping 条纹.然后它在完成后重定向回主页.但是,stripe 说我返回的是 503(我认为这是代码)而不是 200.我正在执行常规的 redirect_to :root.我如何确保也返回 200 代码?
I have a rails app that pings stripe with a new credit card when the user fills out the form. It then redirects back to the homepage when its' done. However, stripe says i'm returning a 503 (i think that's the code) instead of a 200. I'm doing a regular redirect_to :root. How do I make sure to also return a 200 code?
推荐答案
恐怕你不能.
rails 方法
redirect_to some_path
通过向浏览器发送带有 302 的 HTTP 响应来工作状态代码和 URL 目标(作为 HTTP 响应标头).
浏览器收到响应后,会自动向新 URL 发起新的 HTTP 请求.
works by sending to the browser an HTTP response with a 302 status code and an URL destination (as an HTTP response header).
Once the browser receives the response, it will automatically fire a new HTTP request to the new URL.
重定向不会发生在 Rails 中.很多人认为 redirect_to
是一种从控制器的动作跳转到另一个的方法,但它实际上只是要求浏览器发送另一个请求.
The redirection does not happen in Rails. A lot of people think that redirect_to
is a way to jump from a controller's action to another, but it actually just asks the browser to send another request.
现在,浏览器知道如何处理这种响应,因为 302
是一个 HTTP 状态代码.这就是它的意义.您可以将 redirect_to
的状态代码更改为 200
,但这会破坏重定向.
Now, browsers know how to handle this kind of response because 302
is an HTTP status code. That's its meaning. You can change the status code of a redirect_to
to 200
, but that will break the redirection.
这篇关于如何重定向到并返回 200 状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!