Solved

how to use get method?

Posted on 1998-08-24
21
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Six Sigma Control Plans

627 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