Solved

Fake a browser, using LWP module.

Posted on 2000-02-17
6
575 Views
Last Modified: 2008-02-01
Hi, i need to be able to fake a browser post to a php script.
I want to fake a post to, http://www.hooya.com/sendsms.php3. But i have faild. whats wrong with this?

#!/usr/bin/perl

use HTTP::Request::Common qw(POST);
use HTTP::Cookies;
use LWP::UserAgent;


$cookie = new HTTP::Cookies( ignore_discard => 1 );
$ua = new LWP::UserAgent;
$ua->cookie_jar( $cookie );
$ua->agent("Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)");

$myparams{"network"} = "0046703";
$myparams{"cb"} = "ON";
$myparams{"Anzahl"} = "119";
$myparams{"textarea"} = "Jag testar!";
$myparams{"gsm"} = "512221";

my $req = POST 'http://www.hooya.com/sendsms.php3', [ %myparams ];
   $req->push_header(HTTP_REFERER => 'http://www.hooya.com');

$page = $ua->request($req)->as_string;

open OUT,">hooya_log.txt" or die;
print OUT "$page\n";
close OUT;

print $page;

The server, www.hooya.com respons to my post is :

HTTP/1.1 302 (Found) Moved Temporarily
Connection: close
Date: Thu, 17 Feb 2000 20:42:27 GMT
Location: http://www.hooya.com
Server: Apache/1.2.6 Debian/GNU
Content-Type: text/html
Client-Date: Thu, 17 Feb 2000 20:43:23 GMT
Client-Peer: 195.100.21.240:80
Title: 302 Moved Temporarily

<HTML><HEAD>
<TITLE>302 Moved Temporarily</TITLE>
</HEAD><BODY>
<H1>Moved Temporarily</H1>
The document has moved <A HREF="http://www.hooya.com">here</A>.<P>
</BODY></HTML>

Plz help.

Thanxs a lot

/Hansen
0
Comment
Question by:mysig
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2532724
try this.... it works....


==========hooya.pl
#!/usr/local/bin/perl -I/home/webuser/manesh

require LWP;
require URI::URL;

use strict;
use CGI;

my($hdr,$server_response);
my($statement_URL)="http://www.hooya.com/sendsms.php3";

#my($query)=new CGI;

## Right now the values are hard-coded
$hdr="network=0046703&cb=ON&Anzahl=130&textarea=Jag&gsm=512221";

$server_response=&browse($statement_URL,$hdr,3);   ## Fire the URL

print "Content-type: text/html\n\n";

print "$server_response";
   
sub browse(){
   my($statement_URL,$hdr,$page_no)=@_;
   my($content_type,$method);

   $content_type="application/x-www-form-urlencoded";

   $method="GET";

   my($headers)= new HTTP::Headers
     'Content-Type'   =>  $content_type,
     'MIME-Version'   =>  '1.0',
     'Date'           =>  HTTP::Date::time2str(time),
     'Accept'         =>  'text/html';

   my($ua)= new LWP::UserAgent;

   $ua->agent("Mozilla/4.7 [en] (WinNT; U)"); # Define env variable - HTTP_USER
_AGENT

   my($url)= new URI::URL($statement_URL);
   my($request)= new HTTP::Request($method, $url, $headers,$hdr);

   my($response)= $ua->request($request);

   my($reply);

   if ($response->is_success){
      $reply=$response->content;
   }else{
      $reply=$response->error_as_HTML();
   }
   return $reply;
}
0
 

Author Comment

by:mysig
ID: 2535369
It worked with som modifications,

$method="POST";

And under my($headers) i add the following:
'Referer'  =>  'http://www.hooya.com/';

Post it as an answer and i will give u your points.
0
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
ID: 2535551
gotcha!! the resulting output has a small piece of javascript code that checks the no of frames and redirects to home page is the no of frames are not 3.

you can add a small piece of PERL code after line 21 to eliminate that problem too.

@page=split(/\n/,$server_response);

foreach(@page){
  ## here search and remove the javascript code.
}

====================hooya.pl
   +1   #!/usr/local/bin/perl -I/home/webuser/manesh
    +2
    +3   require LWP;
    +4   require URI::URL;
    +5
    +6   use strict;
    +7   use CGI;
    +8
    +9   my($hdr,$server_response);
   +10   my($statement_URL)="http://www.hooya.com/sendsms.php3";
   +11
   +12   #my($query)=new CGI;
   +13
   +14   ## Right now the values are hard-coded
   +15   $hdr="network=0046703&cb=ON&Anzahl=130&textarea=Jag&gsm=512221";
   +16
   +17   $server_response=&browse($statement_URL,$hdr,3);   ## Fire the URL
   +18
   +19   print "Content-type: text/html\n\n";
   +20
   +21   print "$server_response";
   +22
   +23   sub browse(){
   +24      my($statement_URL,$hdr,$page_no)=@_;
   +25      my($content_type,$method);
   +26
   +27      $content_type="application/x-www-form-urlencoded";
   +28
   +29      $method="POST";
   +30
   +31      my($headers)= new HTTP::Headers
   +32        'Content-Type'   =>  $content_type,
   +33        'MIME-Version'   =>  '1.0',
   +34        'Date'           =>  HTTP::Date::time2str(time),
   +35        'Accept'         =>  'text/html',
   +36        'Referer'        =>  'http://www.hooya.com/';
   +37
   +38      my($ua)= new LWP::UserAgent;
   +39
   +40      $ua->agent("Mozilla/4.7 [en] (WinNT; U)"); # Define env variable -
HTTP_USER_AGENT
   +41
   +42      my($url)= new URI::URL($statement_URL);
   +43      my($request)= new HTTP::Request($method, $url, $headers,$hdr);
   +44
   +45      my($response)= $ua->request($request);
   +46
   +47      my($reply);
   +48
   +49      if ($response->is_success){
   +50         $reply=$response->content;
   +51      }else{
   +52         $reply=$response->error_as_HTML();
   +53      }
   +54      return $reply;
   +55   }
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:jasoncolson
ID: 2536959
I'm looking for an ISP that has the LWP module installed.  Any suggestions, guys?
0
 
LVL 84

Expert Comment

by:ozo
ID: 2537049
You might install it yourself.
0
 
LVL 1

Expert Comment

by:fpoyavo
ID: 10617466
Hi,

This line : my($statement_URL)="http://www.hooya.com/sendsms.php3">http://www.hooya.com/sendsms.php3";

gives error : bareword found ......near //www ????

How to fix it ?
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question