#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    North Vancouver, BC, Canada
    Posts
    44
    Rep Power
    14

    Post Https POST sample code


    Hmmm...

    #!/usr/bin/perl

    # requires crypt-ssleay installed
    # OR ERR = 501 Protocol scheme 'https' is not supported
    # SEE : http://www.linpro.no/lwp/
    # windows: ppm install crypt-ssleay [ tested on win98, apache1.3.9, perl 5.60 ]
    # Linux : Crypt-SSLeay-0.27.tar.gz -- read notes requires openssl... basically more required



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

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

    # this is the info we are POST-ing to the script
    $A = "Hello";
    $B = "World";
    $C = "I am";
    $D = "Here";

    # set up the stuff
    my $ua = LWP::UserAgent->new();

    # Set our own user-agent string!
    $ua->agent("PerlZilla/v1.01 RHLinux");

    my $url = "https://www.YourTarget.com/cgi-bin/file.cgi";
    # file.cgi should just return the data sent for this test

    # These seem to be like <input type=text name=A value=$A > off a form...
    my $req = POST $url, [
    A => "$A",
    B => "$B",
    C => "$C",
    D => "$D" # no comma here Eh !
    ];

    # Fire the cannon now !
    my $res = $ua->request($req);

    # Get the error back from the server if any
    my $err = $res->status_line;
    # Get server body text, $_ used in regexp on next line
    $_ = $res->as_string;

    if (/Illegal Operation/ig || $err != 200) {
    print "Server returned error: $err\n";
    exit 1;
    }

    # Just print the whole wack of stuff
    print "$_";
    # RAW info back for debug -- contains header stuff


    exit 0;
    Thanks

    Foot in Mouth ver 1.2.5 Onion
  2. #2
  3. No Profile Picture
    S14x0r
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Location
    Australia
    Posts
    44
    Rep Power
    0
    Hi,

    i have just gone thru all the rigamarol of installing the crypt ssleay module to get posts to work over https. here is a list of all the modules that needed installing

    MIME-Base64-3.00.tar.gz
    URI-1.30.tar.gz
    HTML-Tagset-3.03.tar.gz
    HTML-Parser-3.35.tar.gz
    Crypt-SSLeay-0.51.tar.gz
    libwww-perl-5.76.tar.gz
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    81
    Rep Power
    12

    Nice, but what about ...


    how do you post a file in this way?
  6. #4
  7. Perl Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    May 2003
    Location
    the far end of town where the Grickle-grass grows
    Posts
    1,860
    Rep Power
    109
    If you're in windows and want LWP and SSL, try this: http://johnbokma.com/perl/https.html
    The kicker is the non-standard ppd at http://theoryx5.uwinnipeg.ca/ppms/Crypt-SSLeay.ppd. I guess it isn't included by default so ActiveState doesn't have to worry about encryption exportation laws?

    After that's installed, LWP works transparently with SSL. The ppd copied a pair of DLL's down to perl's bin directory (in path). In my case, I needed to upload a file, a normal text parameter, and post over SSL with basic http authentication. First the html form, then the Perl code to post to it.
    Code:
    <form enctype="multipart/form-data" action="https://url.to/post/to" 
    		method="post">
    	File to process: <input name="FileParamName" type="file"><br>
    	File to process: <input name="FileParamName" type="file"><br>
    	File to process: <input name="FileParamName" type="file"><br>
    	Other form input: 
    	<input name="FileParamName" value="A simple form input value"><br>
    	<input type="submit" value="Upload">
    </form>
    Code:
    use LWP::UserAgent;
    use HTTP::Request::Common;
    my $ua = LWP::UserAgent->new;
    my $req = POST(
          'https://url.to/post/to',
          Content_Type => 'form-data',
          Content      => [ NormalParamName => 'A simple form input value',
                            FileParamName   => ['file-to-upload.txt'],
                          ],
    );
    $req->authorization_basic('username', 'password');
    print $ua->request($req)->as_string;
    I just had to poke at this today and figured I'd share.
    Andrew - Perl (and VB.NET) Monkey

    Never underestimate the bandwidth of a hatchback full of tapes.

IMN logo majestic logo threadwatch logo seochat tools logo