Solved

how to use get method?

Posted on 1998-08-24
21
187 Views
Last Modified: 2010-03-04
Well I'm kinda new at this perl stuff so please bear with me on this.

I have writen the following script:

#!/usr/local/bin/perl



# Receive info from Posting
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);
      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      $value =~ s/<!--(.|\n)*-->//g;
      $value =~ s/<([^>]|\n)*>//g;
      $INPUT{$name} = $value;
}


# Print Follow Up HTML
sub follow_up {

print ("Content-Type: text/html\n\n");
print ("<html><head><title>TEST</title></head>\n");
print ("$INPUT{'name'}.<---------\n");
print ("</body></html>\n");

exit;

}

I would like this script to work wiht the get method instead or as well as the post method. Is this Possible? How do I do it? Could any one re write this for me?

Thanks in advance, david
0
Comment
Question by:fusion123
  • 12
  • 8
21 Comments
 
LVL 4

Expert Comment

by:martinag
ID: 1204499
Replace this:
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
with this:
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
  $buffer = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
  $buffer = "";
  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else {
  # Invalid METHOD.
}

Martin
0
 
LVL 4

Expert Comment

by:martinag
ID: 1204500
At the else statement you will mostly want to print some error message and then exit.

Martin
0
 

Author Comment

by:fusion123
ID: 1204501
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:fusion123
ID: 1204502
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 
LVL 4

Expert Comment

by:martinag
ID: 1204503
In Perl, else if is written as elsif.
Strange, but...

You should replace only that line.

When running, do you get any error messages?

Martin
0
 

Author Comment

by:fusion123
ID: 1204504
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 

Author Comment

by:fusion123
ID: 1204505
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 

Author Comment

by:fusion123
ID: 1204506
ya I get a 500 error
0
 
LVL 4

Expert Comment

by:martinag
ID: 1204507
Here is your new code:

#!/usr/local/bin/perl

# Receive info from Posting
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
  $buffer = $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
  $buffer = "";
  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else {
  # Invalid METHOD.
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$value =~ s/<([^>]|\n)*>//g;
$INPUT{$name} = $value;
}

# Print Follow Up HTML
sub follow_up {
print ("Content-Type: text/html\n\n");
print ("<html><head><title>TEST</title></head>\n");
print ("$INPUT{'name'}.<---------\n");
print ("</body></html>\n");

exit;
}

BTW, I guess this is not your entire script.
You never call follow_up.

Martin
0
 
LVL 4

Expert Comment

by:martinag
ID: 1204508
It works fine for me...

Martin
0
 

Author Comment

by:fusion123
ID: 1204509
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 

Author Comment

by:fusion123
ID: 1204510
elsif should this be else if? And I tried it and it does not seem to work? I must be doing something wrong? Ummmmm... lets see? When you said replace read(STDIN, $buffer, ENV{'CONTENT_LENGTH'}); did you mean just that line or everything below it? Because I tried both and neither worked?  Any sugestions?
0
 
LVL 4

Expert Comment

by:martinag
ID: 1204511
Are you posting that comment all the time?
There's something strange going on around here...

Martin
0
 

Author Comment

by:fusion123
ID: 1204512
OK well like I said perl is not my strenght. I have tried it several different ways including just copying the code you placed online for me and still no luck?

Hmmmmm

you can take a peek if you like

http://www.fusion.ca/cgi-bin/test.cgi
thanks I'm sure really what else to do?

You say it works for you eh?
0
 

Author Comment

by:fusion123
ID: 1204513
OK well like I said perl is not my strenght. I have tried it several different ways including just copying the code you placed online for me and still no luck?

Hmmmmm

you can take a peek if you like

http://www.fusion.ca/cgi-bin/test.cgi
thanks I'm sure really what else to do?

You say it works for you eh?
0
 
LVL 84

Expert Comment

by:ozo
ID: 1204514
#!/usr/local/bin/perl
#does this script work?
print ("Content-Type: text/html\n\n");
print ("<html><head><title>TEST</title></head>\n");
print ("<body>---------\n");
print ("</body></html>\n");
0
 

Author Comment

by:fusion123
ID: 1204515
Yes it does work on it's own.
0
 
LVL 4

Expert Comment

by:martinag
ID: 1204516
You said you got a 500 error...Where does it happen and what does the 500 mean?
Use -w.
Give us the line where the error occures and some of the lines before it.

Martin
0
 

Author Comment

by:fusion123
ID: 1204517
TO  martinag:

hey thanks for your help I figured it out with your help there. <and every one elses thanks> I would like to give you the 100 pts so go a head and lock the question.
0
 
LVL 4

Accepted Solution

by:
martinag earned 100 total points
ID: 1204518
Thank you!

Just curious...what was not working?

Martin
0
 

Author Comment

by:fusion123
ID: 1204519
Thanxs again
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question