gpt4 book ai didi

Perl 催化剂 Controller 重定向不起作用

转载 作者:行者123 更新时间:2023-12-05 01:00:11 31 4
gpt4 key购买 nike

我查看了这段代码,但无法理解它表现出的怪异之处。因为不了解我所知道的一切

$c->res->redirect('qbo/home');

被忽略,支持以下 if else 条件中的重定向。换句话说,我总是在 OAuthentication 网站结束。

如果我阻止注释掉 else 条件,我最终会到达我想去的地方 qbo/home

sub index :Path :Args(0) {
my ($self, $c) = @_;

# Check to see if we have QBO::OAuth object in our user's session
# Create new object in session if we don't already have one
if(!($c->session->{qbo})) {
$c->log->info('Creating QBO::OAuth, save in user session');
$c->session->{qbo} = QBO::OAuth->new(
consumer_key => 'qyprddKpLkOclitN3cJCJno1fV5NzcT',
consumer_secret => 'ahwpSghVOzA142qOepNHoujyuHQFDbEzeGbZjEs3sPIc',
);
}

# Now we set our object variable to the session old or new
my $qbo = $c->session->{qbo};
######### GOTO 'qbo/home' ##########
$c->res->redirect('qbo/home');
####################################
if($c->req->params->{oauth_token}) {
$c->log->info('Now Redirect to access_endpoint');
# Get realmId and save it to our QBO::OAuth object in user session
$qbo->realmId($c->req->params->{realmId});
# Call QBO::OAuth->request_access_token
my $r = $qbo->request_access_token($c->req->params->{oauth_verifier});
$c->res->redirect('qbo/home');
} else {
my $callback = 'http://www.example.com/qbo';
# Request a token
my $r = $qbo->request_token($callback);
if($qbo->has_token) {
#Continue on down, Redirect to auth_user_endpoint
$c->res->redirect($qbo->auth_user_endpoint . '?oauth_token=' . $qbo->token);
}
}
}

似乎我缺少有关其工作原理的一些基本原理。任何线索表示赞赏

最佳答案

来自fine manual ...

This is a convenience method that sets the Location header to the redirect destination, and then sets the response status. You will want to return or $c->detach() to interrupt the normal processing flow if you want the redirect to occur straight away.

另请注意该手册页上有关重定向到相对 URL 的警告 - 您不应该这样做。对于您的用例,我建议您养成使用的习惯:

return $c->res->redirect($c->uri_for('qbo/home'));

$c->res->redirect($c->uri_for('qbo/home')) && $c->detach();

取决于您的喜好。

关于Perl 催化剂 Controller 重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39397059/

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