469,357 Members | 1,542 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

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:
Expand|Select|Wrap|Line Numbers
  1. #!c:\perl\bin\perl.exe
  2.  
  3. use CGI qw(:standard);
  4. use LWP::UserAgent;
  5. use CGI;
  6.  
  7. my $url="http://search.cpan.org/";
  8.  
  9. print header;
  10.  
  11. require LWP::UserAgent;
  12.  
  13. my $query=new CGI;
  14. my $ua =LWP::UserAgent->new;
  15.  
  16. $ua->env_proxy();
  17.  
  18. $response=$ua->get($url);
  19.  
  20. $conn=$response->content;
  21. print $conn;
  22.  
  23. my $res = $ua->request($conn);
  24.  
  25. #print start_html;
  26. print<<HTML;
  27. <title>info</title>
  28. <body>
  29. HTML
  30.  
  31. print $conn;
  32.  
  33. print "</html></body>";
  34. if ($res->is_success)
  35. {
  36.     print "success";
  37.     print "$conn";
  38.     #print $query->redirect("http://first.server/index.php");
  39. else 
  40. {
  41.         #print $query->redirect("http://second.server/index.php");
  42. }
Thankyou
Sep 26 '06 #1
2 1224
eWish
971 Expert 512MB
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
Nov 19 '07 #2
KevinADC
4,059 Expert 2GB
Also, make sure your firewall (if any) is not blocking.
Nov 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by G-Fit | last post: by
11 posts views Thread by pradeep_TP | last post: by
6 posts views Thread by Chris Szabo | last post: by
18 posts views Thread by Rob Nicholson | last post: by
35 posts views Thread by Eric Sabine | last post: by
3 posts views Thread by Martin B | last post: by
20 posts views Thread by fniles | last post: by
3 posts views Thread by fniles | last post: by
reply views Thread by Robert Avery | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.