CGI header problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajiv07
    New Member
    • Jun 2007
    • 141

    CGI header problem

    Hi to all

    I have a script to get geo IP which is successfully running on Linux server.but when i run this script on windows server it gives some header error

    [CODE=perl]#!C:/Perl/bin/perl.exe
    use CGI qw/:standard/;
    use LWP::UserAgent;
    use HTTP::Request qw(GET POST);
    use HTTP::Headers;

    use CGI::Cookie;
    use CGI::Session;

    use CGI::Carp qw(fatalsToBrow ser);

    my $q=new CGI;

    my $c=new CGI::Cookie;

    my $cIP = $ENV{'REMOTE_AD DR'} ;

    # replace this value with license key
    my $license_key ="key";


    my $ua = LWP::UserAgent->new(timeout =>10);

    my $h = HTTP::Headers->new;

    $h->content_type(' application/x-www-form-urlencoded');

    my $request = HTTP::Request->new('POST','ht tp://maxmind.com:801 0/a',
    $h,"l=$license_ key&i=$cIP");
    my $res = $ua->request($reque st);

    my $content = $res->content;
    #print "Content-type: text/html\n\n" ;
    ############ again send request #######
    if($content eq "")
    {
    sleep(1);

    $request = HTTP::Request->new('POST','ht tp://maxmind.com:801 0/a',
    $h,"l=$license_ key&i=$cIP");
    $res = $ua->request($reque st);

    $content = $res->content;
    }
    if($content eq "")
    {
    sleep(1);

    $request = HTTP::Request->new('POST','ht tp://maxmind.com:801 0/a',
    $h,"l=$license_ key&i=$cIP");
    $res = $ua->request($reque st);

    $content = $res->content;
    }
    if($content eq "")
    {
    $content="Serve r-Error";
    }

    my $session = "" ;

    my $sid = "" ;

    $sid = _Checkcookie();

    if($sid eq "")
    {
    $session = new CGI::Session("d river:File", $q, {Directory=>'/tmp'});

    my $server = $ENV{'HTTP_HOST '};

    my $path = "/";

    $sid = $session->id();

    print "Set-Cookie: CGISESSID\=$sid ; path\=$path;dom ain\=$server\n" ;
    }
    else
    {
    $session = new CGI::Session(un def, $sid, {Directory=>'/tmp'});
    }

    my $cFlag = 0 ;

    my $referer=$q->param('referer ');

    my $albumid=$q->param('albumid ');

    my $action=$q->param('action' );

    my $shopping_info= $session->param('shoppin g_info');

    my %shopping_info= %{$shopping_inf o};

    $shopping_info{ geo}=$content;


    $session->param("shoppin g_info",\%shopp ing_info);

    $session->expire('+12h') ;

    if($action eq "direct"){
    #print "location: /cgi-bin/elearning/query/el_alb_details. pl?albumid=$alb umid&action=geo \n\n" ;
    print "Status: 302 Moved", "\r\n","Locatio n: http://www.mysitename. com/cgi-bin/elearning/query/el_alb_details. pl?albumid=$alb umid&action=geo ", "\r\n\r\n";
    exit;
    }

    print 'Status: 302 Moved', "\r\n",'Locatio n:/cgi-bin/elearning/query/el_show_cat.pl' , "\r\n\r\n";

    exit;

    sub _Checkcookie{

    my %cookies=fetch CGI::Cookie;

    my $name=$cookies{ CGISESSID};

    my @temp=split(/CGISESSID\=/,$name);

    my @temp1=split(/;/,$temp[1]);

    return $temp1[0];
    }[/CODE]

    My error

    The specified CGI application misbehaved by not returning a complete set of HTTP headers.

    Please help on this

    Thanks in advance
    Rajiv
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    for now do this, change these lines:

    Code:
    print 'Status: 302 Moved', "\r\n",'Location:/cgi-bin/elearning/query/el_show_cat.pl', "\r\n\r\n";
    to:

    Code:
    print 'Location: http://www.yoursite.com/cgi-bin/elearning/query/el_show_cat.pl', "\r\n\r\n";
    and see if that gets the script running. If it does, the problem is in the header your script is printing. If not, I don't know what the problem is.

    Comment

    • rajiv07
      New Member
      • Jun 2007
      • 141

      #3
      Thanks Kevin,

      Actually i am trying to move all script from Linux Server to windows server.No program is work.All script gives the same error.i could not find any problem.But when i run a simple test script its working fine.

      My testing script

      [CODE=perl]#!C:/perl/bin/perl.exe
      use CGI qw/:standard/;

      use CGI::Carp qw(fatalsToBrow ser);

      my $q=new CGI;

      my $cFlag = 0 ;

      my $referer=$q->param('referer ');

      my $albumid=$q->param('albumid ');

      my $action=$q->param('action' );

      print $q->header;

      print "Hello world";

      exit;

      [/CODE]

      Is any server configuration fault has involved in this problem.

      Plesae suggest me any idea or solution please.

      Thanks in advance

      Rajiv

      Comment

      Working...