PDA

View Full Version : using POST in Perl. Please HELP!


uniprosper
12-17-1998, 03:18 PM
Hi,

I wondered if anyone could give me any help as to how I use the POST method in Perl.

What I'm trying to do is open a socket connection with another server, and post information to a file on their server using the POST method. I know how to do this in HTML, but I don't want to do that because I want the Perl script to be able to do it automatically.

I also know how to use the GET method in Perl, even when opening a socket connection to another server, but I just can't figure out how to post form contents to a another server using Perl.

Any ideas? Please let me know. All helpful information will receive a FREE website promotional package for their site, so now you have a reason to post a response!

This is the GET method I'm using at the minute in my Perl script:

openconnection("http://serverhere.com","80");

$add"$/path/to/file/here";
$submit = "GET $add HTTP/1.0\n\n";

send(SOCK,$submit,0);
close(SOCK);

Any ways to convert this to a POST method and mail form contents to this file?

Like I said, all helpful responses will receive a REWARD, worth $29.95
(submission to over 5,000 search engines and FFA site, plus a FREE advert in my E-Zine which is sent to 3000+ people!)

And Merry Christmas!
Lee.
lee.benson@diamond.co.uk

Terra
12-17-1998, 03:53 PM
I would *highly* recommend using the Perl LWP library...

It has a layer of abstraction that is *very* hard to beat when dealing with the 'http:', 'ftp:', 'nntp:', 'pop:', etc..etc.. protocols...

Once you get the hang of LWP, you can toss away all the socket munging and utilize the Internet via OOP methods...

--
Terra
sysAdmin
FutureQuest.net

PS: Did I fail to mention that I always keep the LWP module up to date, as I use it frequently myself...
$man LWP

http://www.aota.net/ubb/wink.gif

uniprosper
12-17-1998, 04:06 PM
Hi,

Thanks for your reply.
That sounds good. I'll try and find some
info of that.

Do you know how to specifically use the POST
method with http protocols with these
libraries?

Thanks,
Lee.

meikel
12-17-1998, 07:46 PM
Hi,

I think you are looking for this code

$submit ="POST /cgi-bin/x.pl HTTP/1.0\n";
$submit.="Content-length: 100\n";
$submit.="Content-type: text/plain\n\n";
$submit.=$Some100Bytes;

I have never tested this, but as I understand that HTTP spec, that should do it. I'm not sure if the Content-type line is needed. You should match the Content-type and the data (so I don't know if it's ok to send a binary via text/plain).

Greetings from Bonn, Germany
Meikel Weber
http://www.meikel.com

uniprosper
12-19-1998, 06:34 PM
Thanks, I'll try that code out.

If it works, then that will help alot. And as a thanks for helping me, you can sign-up to my submission service at http://www.uniprosper.com free and get 5,000 free submission credits.

Merry Christmas!
Lee.

------------------
=======================
Get FREE promotion &
BOOST TRAFFIC NOW!
http://www.uniprosper.com
=========================

Terra
01-11-1999, 05:09 PM
I was rummaging around in my '/usr/bin' directory and found something that might help you...

The program is '/usr/bin/POST'... Feel free to copy it to your personal directory and look at it... I think this will help you utilize the LWP library for formulating POST methods...

--
Terra
--resource locater--
FutureQuest

uniprosper
01-11-1999, 05:31 PM
Thanks Terra,

I will take a look at that.
I'm still determined to get this thing
done!

Thanks again. much appreciated.
Lee

------------------
=========================
http://www.uniprosper.com
=========================
"If at first you don't succeed,
call it Version 1.0"

[This message has been edited by uniprosper (edited 01-11-99).]

jbroder
01-11-1999, 07:29 PM
Terra,
What is lwp?

I am looking into using post to let my
users submit files to my site and have run across a thing called cgi_lib from a guy at stanford.

Is lwp a similar library-type thing?

Thanks in advance.

Jon

Terra
01-11-1999, 10:44 PM
LWP is a *massive* WWW library for Perl... Anything that deals with URL/URI can be found in here...

It is as breathtaking, the capability, as the CGI library is...

I highly recommend that you research:
http://www.sn.no/libwww-perl/

I have even written my own little browser with the LWP libraries - and I always keep this one up to date...

--
Terra
System Coder
FutureQuest

uniprosper
01-12-1999, 03:52 AM
wow, it sounds great.
I'm definately researching into this one.

Thanks again,
Lee.

------------------
=========================
http://www.uniprosper.com
=========================
"If at first you don't succeed,
call it Version 1.0"