302运行Perl脚本时找到

时间:2013-09-02 05:07:16

标签: perl cgi

#!/usr/bin/perl -w

use WWW::Facebook::API;
use WWW::Facebook::API::Auth;
use WWW::Facebook::API::Canvas;
use HTTP::Request;
use LWP;

use CGI;                                # load CGI routines
$q = CGI->new;                          # create new CGI object
print $q->header,                       # create the HTTP header
  $q->start_html('Facebook App'),       # start the HTML
  $q->h1('Facebook Authentication'),    # level 1 header
  $q->end_html;                         # end the HTML

my $facebook_api      = '---------------';
my $facebook_secret   = '----------------------------';
my $facebook_clientid = '-----------------------------------';

my $client = WWW::Facebook::API->new(
    desktop     => 0,
    api_version => '1.0',
    api_key     => $facebook_api,
    secret      => $facebook_secret,

);

$client->app_id($facebook_clientid);
print $q->redirect( $client->get_login_url() );

在显示为

的Web浏览器中
Facebook Authentication
Status: 302 Found Location: http://www.facebook.com/login.php? api_key= -  ----------------&v=1.0 

如何修复此CGI问题。我在ubuntu apache服务器上运行这个perl脚本。

1 个答案:

答案 0 :(得分:4)

您可以在此处打印HTTP标头:

print $q->header

然后在这里打印另一个HTTP标头:

print $q->redirect($client->get_login_url());

HTTP消息只能有一组标头。如果你要发送302重定向,那么也不需要打印任何HTML,所以要摆脱所有这些:

print $q->header,                         # create the HTTP header
$q->start_html('Facebook App'),       # start the HTML
$q->h1('Facebook Authentication'),    # level 1 header
$q->end_html;                         # end the HTML