gpt4 book ai didi

ruby - 如何将请求转发到 Sinatra 中的不同端点

转载 作者:数据小太阳 更新时间:2023-10-29 08:44:35 25 4
gpt4 key购买 nike

我有一个端点单独负责所有表单提交;这个端点然后将数据发送到表单提交中的数据给它的正确端点(例如,从隐藏字段)。

我知道将数据发送到哪里:

post to /account 

如何在不重定向的情况下将服务器接收的数据直接转发到同一服务器上的另一个端点?

还是使用像 curb 或 rest-client 这样的 HTTP 客户端的唯一方法?

最佳答案

它看起来不太好,但你可以尝试这样的事情:

post "/account" do
call! env.merge('PATH_INFO' => "/another/endpoint")
end

post "/another/endpoint" do
...
end

但通常最好提取 /another/endpoint 中的任何代码并直接从 /account 端点调用它。例如:

post "/account" do
process_data(...)
end

post "/another/endpoint" do
process_data(...)
end

def process_data(...)
...
end

关于ruby - 如何将请求转发到 Sinatra 中的不同端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33576545/

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