connection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Archanak
    New Member
    • Sep 2006
    • 79

    connection

    hi,
    I have a problem connecting to the sites using LWP::UserAgent the code is working fine in command prompt but through cgi in browser it is giving an error:
    500 cant connect to :80(unknown error)my code is here:
    [CODE=perl]#!c:\perl\bin\p erl.exe

    use CGI qw(:standard);
    use LWP::UserAgent;
    use CGI;

    my $url="http://search.cpan.org/";

    print header;

    require LWP::UserAgent;

    my $query=new CGI;
    my $ua =LWP::UserAgent->new;

    $ua->env_proxy();

    $response=$ua->get($url);

    $conn=$response->content;
    print $conn;

    my $res = $ua->request($conn) ;

    #print start_html;
    print<<HTML;
    <title>info</title>
    <body>
    HTML

    print $conn;

    print "</html></body>";
    if ($res->is_success)
    {
    print "success";
    print "$conn";
    #print $query->redirect("http ://first.server/index.php");
    }
    else
    {
    #print $query->redirect("http ://second.server/index.php");
    }[/CODE]

    Thankyou
    Last edited by eWish; Nov 19 '07, 02:20 AM. Reason: Added Code Tags & Fixed Format
  • eWish
    Recognized Expert Contributor
    • Jul 2007
    • 973

    #2
    You have several issues. You don't need to have 'require LWP::UserAgent' when using 'use LWP::UserAgent; ' Also, you need to use either 'use CGI qw(:standard);' or 'use CGI;'

    If you had used the CGI::Carp module along with the strict and warnings pragmas you would have been able to detect most of your issues. Read about the difference between use and require.


    --Kevin

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      Also, make sure your firewall (if any) is not blocking.

      Comment

      Working...