Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how can perl respond to someone's HTTP POST

Reply
Thread Tools

how can perl respond to someone's HTTP POST

 
 
Jack
Guest
Posts: n/a
 
      05-29-2009
Hi there,

Simple concept but its not clear anywhere how to implement a response
to a server (that has posted to my server) with some result. does
anyone know how, is a CPAN module required to do this ? I have seen
LWP for posting, but its not clear how to RESPOND to somebody's post
to my server...

thank you,
Jack
 
Reply With Quote
 
 
 
 
Lars Eighner
Guest
Posts: n/a
 
      05-29-2009
In our last episode,
<(E-Mail Removed)>, the
lovely and talented Jack broadcast on comp.lang.perl.misc:

> Hi there,


> Simple concept but its not clear anywhere how to implement a response
> to a server (that has posted to my server) with some result. does
> anyone know how, is a CPAN module required to do this ? I have seen
> LWP for posting, but its not clear how to RESPOND to somebody's post
> to my server...


Your post does not clearly indicate to me that you know the difference
between the several sense of the word "post." So I will say something about
the part that most nearly has something to do with perl.

In this situation:

You have set up a web page which contains an HTML form using the POST
method.

Perhaps you are asking:

In perl how do I do what should be done with the POST data and get the
server to send a page with some response to the data that has been recieved
via POST?

In that case the answer is something like this:

look for your answer in man CGI (unix-like systems) or perldoc CGI (any
system with perl installed). The CGI module has been part of the core
distribution for some time. You may find some additional help in section 9
of the FAQ "Networking." You can use the CGI module without an especially
deep understanding of what is going on behind the scenes.

Eventually you should understand that the perl CGI module is an easy way to
do CGI with perl, but neither perl nor CGI.pm (the module) is CGI. CGI is
the standard for getting servers and executables to interact. Just about
any executable that can write to stdout can be coerced into complying with
CGI, and that includes perl without the CGI module.

If the man page (or perldoc) is not enough help, you should be able to
google up a number of tutorials with keywords like perl, CGI, tutorial.

Whether any kind of CGI (perl, C, sh, php-cgi, etc.) will work for you at
all depends upon your server and configuration. So if you try to work
through a tutorial and cannot get your test documents to work at all, you
need to look at your server and its requirements.


--
Lars Eighner <http://larseighner.com/> http://www.velocityreviews.com/forums/(E-Mail Removed)
128 days since Rick Warren prayed over Bush's third term.
Obama: No hope, no change, more of the same. Yes, he can, but no, he won't.
 
Reply With Quote
 
 
 
 
Mart van de Wege
Guest
Posts: n/a
 
      05-29-2009
Jack <(E-Mail Removed)> writes:

> Hi there,
>
> Simple concept but its not clear anywhere how to implement a response
> to a server (that has posted to my server) with some result. does
> anyone know how, is a CPAN module required to do this ? I have seen
> LWP for posting, but its not clear how to RESPOND to somebody's post
> to my server...
>

Well, if you know how the other end handles your client LWP POSTs, then
you should have a good clue...

In short, you have to write a HTTP server, or hook into an existing
one. Perl has the tools to do both, but before I go into details, I
really need to know what you do have on your end. Do you have a HTTP
server already running? If yes, which one?

Mart

--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
 
Reply With Quote
 
Jack
Guest
Posts: n/a
 
      05-29-2009
On May 29, 12:21*am, Mart van de Wege <(E-Mail Removed)> wrote:
> Jack <(E-Mail Removed)> writes:
> > Hi there,

>
> > Simple concept but its not clear anywhere how to implement a response
> > to a server (that has posted to my server) with some result. *does
> > anyone know how, is a CPAN module required to do this ? *I have seen
> > LWP for posting, but its not clear how to RESPOND to somebody's post
> > to my server...

>
> Well, if you know how the other end handles your client LWP POSTs, then
> you should have a good clue...
>
> In short, you have to write a HTTP server, or hook into an existing
> one. Perl has the tools to do both, but before I go into details, I
> really need to know what you do have on your end. Do you have a HTTP
> server already running? If yes, which one?
>
> Mart
>
> --
> "We will need a longer wall when the revolution comes."
> --- AJS, quoting an uncertain source.


Hi I am using a Windows Server 2003 system running IIS. I have other
computers on the web that will be posting to a URL of mine (a perl ASP
webpage), and that webpage acquires those posted variables, does a
database lookup, and all I want to do is return the lookup results to
the other system that requested it via a post.. ! Basic. is this
possible, or do I just simply post back to the other server. I am
familiar with using LWP for posting to a URL, but again, I have no
idea, and would like to see the code, to provide a direct REPLY with
data back to the poster. I am not looking for a digression on "man
CGI", as the first poster indicated.
Thank you !

Jack
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      05-29-2009
In article
<(E-Mail Removed)>,
Jack <(E-Mail Removed)> wrote:

> Hi there,
>
> Simple concept but its not clear anywhere how to implement a response
> to a server (that has posted to my server) with some result. does
> anyone know how, is a CPAN module required to do this ? I have seen
> LWP for posting, but its not clear how to RESPOND to somebody's post
> to my server...


A server that is posting a request to your server is acting as a
client. The way to generate a dynamic response to that request is to
have the URL of the request point to a program (or programmable page)
instead of a static page. The CGI protocol is one way to do this. There
are others: ASP, JSP, PHP, etc.

LWP is a client system that may be used to emulate a browser. It does
not respond to requests.

--
Jim Gibson
 
Reply With Quote
 
Jack
Guest
Posts: n/a
 
      05-29-2009
On May 29, 8:29*am, Jim Gibson <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
>
> Jack <(E-Mail Removed)> wrote:
> > Hi there,

>
> > Simple concept but its not clear anywhere how to implement a response
> > to a server (that has posted to my server) with some result. *does
> > anyone know how, is a CPAN module required to do this ? *I have seen
> > LWP for posting, but its not clear how to RESPOND to somebody's post
> > to my server...

>
> A server that is posting a request to your server is acting as a
> client. The way to generate a dynamic response to that request is to
> have the URL of the request point to a program (or programmable page)
> instead of a static page. The CGI protocol is one way to do this. There
> are others: ASP, JSP, PHP, etc.
>
> LWP is a client system that may be used to emulate a browser. It does
> not respond to requests.
>
> --
> Jim Gibson


Exactly..BUT, how exactly do I have the Perl/ASP page respond back ?
"print" to the page ? Trying to get tactical level here, ie code.
 
Reply With Quote
 
Mart van de Wege
Guest
Posts: n/a
 
      05-29-2009
Jack <(E-Mail Removed)> writes:

> On May 29, 12:21*am, Mart van de Wege <(E-Mail Removed)> wrote:
>> Jack <(E-Mail Removed)> writes:
>> > Hi there,

>>
>> > Simple concept but its not clear anywhere how to implement a response
>> > to a server (that has posted to my server) with some result. *does
>> > anyone know how, is a CPAN module required to do this ? *I have seen
>> > LWP for posting, but its not clear how to RESPOND to somebody's post
>> > to my server...

>>
>> Well, if you know how the other end handles your client LWP POSTs, then
>> you should have a good clue...
>>
>> In short, you have to write a HTTP server, or hook into an existing
>> one. Perl has the tools to do both, but before I go into details, I
>> really need to know what you do have on your end. Do you have a HTTP
>> server already running? If yes, which one?
>>
>> Mart
>>

>
> Hi I am using a Windows Server 2003 system running IIS. I have other
> computers on the web that will be posting to a URL of mine (a perl ASP
> webpage), and that webpage acquires those posted variables, does a
> database lookup, and all I want to do is return the lookup results to
> the other system that requested it via a post.. ! Basic. is this
> possible, or do I just simply post back to the other server. I am
> familiar with using LWP for posting to a URL, but again, I have no
> idea, and would like to see the code, to provide a direct REPLY with
> data back to the poster. I am not looking for a digression on "man
> CGI", as the first poster indicated.
> Thank you !



First off, snip signatures, please.

Second, a digression on CGI is *exactly* what you need.

On the gripping hand, I don't know anything about Windows and IIS, so
how you would go about serverside programming in that environment I am
going to have to leave to someone else.

Mart

--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
 
Reply With Quote
 
Jack
Guest
Posts: n/a
 
      05-29-2009
On May 29, 8:55*am, Glenn Jackman <(E-Mail Removed)> wrote:
> At 2009-05-29 11:08AM, "Jack" wrote:
> [...]
>
> > *Hi I am using a Windows Server 2003 system running IIS. *I have other
> > *computers on the web that will be posting to a URL of mine (a perl ASP
> > *webpage), and that webpage acquires those posted variables, does a
> > *database lookup, and all I want to do is return the lookup results to
> > *the other system that requested it via a post.. ! *Basic. *is this
> > *possible, or do I just simply post back to the other server. *I am
> > *familiar with using LWP for posting to a URL, but again, I have no
> > *idea, and would like to see the code, to provide a direct REPLY with
> > *data back to the poster. *I am not looking for a digression on "man
> > *CGI", as the first poster indicated.

>
> If you had given us these details in the first place, you might have
> been spared that horrifying "digression"
>
> Let your web server do it's job. *Your asp page doesn't have to worry
> about how the request got to it -- it just needs to return some content.
>
> What format for the data are you supposed to provide? *Will CSV do?
>
> IMO, your asp should output a Content-Type: text/plain header followed
> by properly-quoted CSV data.
>
> --
> Glenn Jackman
> * * Write a wise saying and your name will live forever. -- Anonymous


Thanks ! actually it will output XML, but just knowing how to output
anything is a start - what is the code I need to provide so this
happens ?? My ASP page does a database lookup, then what is the code
I need to hand off the contents of these variables to something ??
 
Reply With Quote
 
Steve C
Guest
Posts: n/a
 
      05-29-2009
Jack wrote:
> On May 29, 8:29 am, Jim Gibson <(E-Mail Removed)> wrote:
>> In article
>> <(E-Mail Removed)>,
>>
>> Jack <(E-Mail Removed)> wrote:
>>> Hi there,
>>> Simple concept but its not clear anywhere how to implement a response
>>> to a server (that has posted to my server) with some result. does
>>> anyone know how, is a CPAN module required to do this ? I have seen
>>> LWP for posting, but its not clear how to RESPOND to somebody's post
>>> to my server...

>> A server that is posting a request to your server is acting as a
>> client. The way to generate a dynamic response to that request is to
>> have the URL of the request point to a program (or programmable page)
>> instead of a static page. The CGI protocol is one way to do this. There
>> are others: ASP, JSP, PHP, etc.
>>
>> LWP is a client system that may be used to emulate a browser. It does
>> not respond to requests.
>>
>> --
>> Jim Gibson

>
> Exactly..BUT, how exactly do I have the Perl/ASP page respond back ?
> "print" to the page ? Trying to get tactical level here, ie code.



The way the CGI protocol works is that the web server (IIS) receives the
request and calls the perl program on the server, which outputs HTML to
stdout. That output is captured by the web server and returned to the
requester.

The perl CGI module does some of the work for you, like hiding whether the
request is GET or POST. There are many tutorials about CGI available,
here is one:
http://support.microsoft.com/kb/245225
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      05-30-2009

"Jack" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi there,
>
> Simple concept but its not clear anywhere how to implement a response
> to a server (that has posted to my server) with some result. does
> anyone know how, is a CPAN module required to do this ? I have seen
> LWP for posting, but its not clear how to RESPOND to somebody's post
> to my server...
>
> thank you,
> Jack


Hi. I've cut and pasted from my own code.
I guess this is what you need.
Regards
John


#!/usr/bin/perl
# Perl 5.8.8
# MySQL 5.0.32

use lib '../'; # parent directory
use strict;
use warnings;
use XML::Simple; $XML::Simple:REFERRED_PARSER='XML:arser';
my $xmlsimple=new XML::Simple (ForceArray=>1, SuppressEmpty=>'',
KeyAttr=>[]); # create object

# ------------------------------------------------------------------------------------------

my $length=$ENV{'CONTENT_LENGTH'};
my $request; my $response;
read (STDIN,$request,$length); # XML request from client
my $data=$xmlsimple->XMLin($request); # parse XML string

my $username=$data->{'username'}->[0];
my $password=$data->{'password'}->[0];
my $number=$data->{'number'}->[0];

if ($username ne 'whatever') {$response="
<whatever-response>
<error-message>invalid username</error-message>
</whatever-response>"
}
else {$response="
<whatever-response>
<company-name>Whatever Limited</company-name>
<company-address>Whatever Town</company-address>
<error-message></error-message>
</whatever-response>"
}

my $len=length($response);

# send 200 back to client via STDOUT - note blank line

print <<END;
Status: 200 OK
Content-type: application/xml;charset=UTF-8
Accept: application/xml;charset=UTF-8
Content-length: $len

$response
END

# ------------------------------------------------------------------------------------------

1; # last statement executed must be true

__END__



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
HTTP SOAP/HTTP GET/HTTP POST milan_9211 Software 0 01-10-2011 02:10 PM
Respond to HTTP Post starshipRobot ASP .Net 0 01-13-2010 05:19 PM
HTTP::Post - HTTP::Get (Can someone help me?) Fred Ruby 17 04-25-2008 07:12 PM
'http://localhost/ doesn't respond with the default page Sunny via .NET 247 ASP .Net 0 04-27-2004 01:15 AM



Advertisments