Solved

how to use get method?

Posted on 1998-08-24
21
194 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
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…

820 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