Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to use get method?

Posted on 1998-08-24
21
Medium Priority
?
214 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 85

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 400 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans

963 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