I have two CGI scripts written in Perl and I want to implement the following communication sequence between the two. Script A sends a POST request to script B, it should then wait for B to perform some type of validation by querying a Database, then B sends success or failure back to A along with a custom code e.g. 1122 specific to my application and A continues execution as appropriate. Is this something that can be achieved using the LWP framework ?
I have tried to send a POST request from A to B and then wait in script A using
while(<STDIN>) {
$response .= $_;
}
until it receives an answer back from B (another POST) but this does not work as A simply ignores the SDTIN loop and continues anyway.
Needless to say I am completely new to to CGI and most answers I have found involve a simple POST or GET request to a CGI script but not a two way communication where one end has to wait for the other to respond after a validation has taken place.
You don't need to do anything to make the script wait for a response. LWP is synchronous by default.
Just make the request, and then read $res->content;
(not STDIN!) as normal (see the documentation for an extended example).
You shouldn't be touching STDIN directly at all if you are working with CGI. Ideally you will be using Plack/PSGI so you will be accessing all input through the Plack API (or a framework built on top of it). If you are working with legacy code, then you will probably be using CGI.pm which provides its own API for reading input (through param
).
Needless to say I am completely new to to CGI and most answers I have found involve a simple POST or GET request to a CGI script but not a two way communication where one end has to wait for the other to respond after a validation has taken place.
You are making a simple POST or GET request.
A.cgi
A.cgi
makes request to B.cgi
B.cgi
outputs a responseA.cgi
reads that response and does something with itA.cgi
outputs a response