Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 19th, 2001, 11:31 PM
footinmouth footinmouth is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: North Vancouver, BC, Canada
Posts: 44 footinmouth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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

Reply With Quote
  #2  
Old February 12th, 2004, 08:30 PM
blobon blobon is offline
S14x0r
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Australia
Posts: 44 blobon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 55 sec
Reputation Power: 0
Send a message via ICQ to blobon
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

Reply With Quote
  #3  
Old February 13th, 2004, 05:47 PM
jimo9 jimo9 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 81 jimo9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 41 sec
Reputation Power: 6
Nice, but what about ...

how do you post a file in this way?

Reply With Quote
  #4  
Old October 4th, 2004, 03:19 PM
icrf's Avatar
icrf icrf is offline
Perl Monkey
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: May 2003
Location: the far end of town where the Grickle-grass grows
Posts: 1,856 icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level)icrf User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 10 h 28 m 31 sec
Reputation Power: 103
Send a message via AIM to icrf
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Https POST sample code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT