Link to home
Start Free TrialLog in
Avatar of mysig
mysig

asked on

Fake a browser, using LWP module.

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
Avatar of maneshr
maneshr

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;
}
Avatar of mysig

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of maneshr
maneshr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm looking for an ISP that has the LWP module installed.  Any suggestions, guys?
Avatar of ozo
You might install it yourself.
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 ?