works for GET, not POST
[1/13] from: rchristiansen:pop:isdfa:sei-it at: 19-Jan-2001 17:19
I'm using the following function, which is derived from the "Official
Guide," for CGI.
retrieve-user-data: func [] [
return make object! decode-cgi
either system/options/cgi/request-method = "POST" [
input
][
system/options/cgi/query-string
]
]
I use it as such:
cgi-input: retrieve-user-data
to give me an object containing the input values.
My usage is working for GET operations but not for POST. What am
I doing wrong?
-Ryan
[2/13] from: gjones05:mail:orion at: 20-Jan-2001 6:45
Ryan,
It appears as though you will need to read from system/ports/input to
receive the actual POST query data. This process is explained in more
detail in the "REBOL/Core User's Guide," which is available in pdf format
online at:
http://www.rebol.com/download_manual.html
or the print version is available through www.rebolpress.com .
The relevent section begins on page 402, with POST explained on the
following two pages.
Hope this helps.
- Scott
[3/13] from: gjones05:mail:orion at: 31-Jan-2001 13:32
Elan,
Thanks for the explanation about the use of "make object!" in the context of
managing CGI GET and POSTs. It does help me to understand why it was used,
and it also gives me a better strategy for managing data sets in the future.
--Scott
Elan wrote:
[4/13] from: rebol:techscribe at: 30-Jan-2001 13:04
Hi Ryan,
I don't understand why you are having problems (haven't followed this
thread).
I am routinely using the following function with POST under an Apache
Webserver on Linux using REBOL/Core current stable version and it works
without complaints every time:
retrieve-user-data: func [] [
return decode-cgi
either system/options/cgi/request-method = "POST" [
input
][
either system/options/cgi/query-string [
system/options/cgi/query-string
][
""
]
]
]
Which problems are you having?
Take Care,
Elan
Ryan C. Christiansen
wrote:
[5/13] from: gjones05:mail:orion at: 30-Jan-2001 16:41
Hi, Ryan,
It can be frustrating sometimes.
I just got the following code running on Windows 98, with Apache 1.3.14.
The form file is arbitrarily named "rebolcgiform2.html". Place it in a
web-accessible directory.
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<TITLE>untitled</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<FORM ACTION="/cgi-bin/query.r" METHOD="POST">
<H2><FONT FACE="Arial, Helvetica">CGI Form Example</FONT></H2>
<P>
<TABLE BORDER="1" CELLSPACING="1" WIDTH="75%" BGCOLOR="silver">
<TR>
<TD WIDTH="9%" BGCOLOR="#66CCFF">
<P ALIGN="RIGHT"><B>Name:</B>
</TD>
<TD><INPUT TYPE="TEXT" NAME="name" SIZE="40"></TD>
</TR>
<TR>
<TD WIDTH="9%" BGCOLOR="#66CCFF">
<P ALIGN="RIGHT"><B>Email:</B>
</TD>
<TD><INPUT TYPE="TEXT" NAME="email" SIZE="40"></TD>
</TR>
<TR>
<TD WIDTH="9%" BGCOLOR="#66CCFF">
<P ALIGN="RIGHT"><B>Phone:</B>
</TD>
<TD><INPUT TYPE="TEXT" NAME="phone" SIZE="20"></TD>
</TR>
</TABLE>
</P>
<P><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit">
</FORM>
</BODY>
</HTML>
Now, the REBOL script file is arbitrarily named "query.r". Place it in the
cgi-bin directory.
#!c:/program files/rebol/rebol -cs
REBOL []
retrieve-user-data: func [] [
return decode-cgi
either system/options/cgi/request-method = "POST" [
data: make string! 2002
foreach line copy system/ports/input [
repend data [line newline]
]
][
either system/options/cgi/query-string [
system/options/cgi/query-string
][
""
]
]
]
print "Content-Type: text/html^/"
print [
<HTML><BODY>
{Here is the posted data.}
<HR><PRE>(retrieve-user-data)</PRE>
</BODY></HTML>
]
If another directory has been designated as the executable directory, then
you will need to change the path in the form. The path to rebol located at
the top of the script may need to be changed depending on the platform. The
webserver may need to be configured to accept the .r extension as an
executable file, especially on Windows. If on UNIX, the file permissions
will need to be changed to allow for reading and execution. If you cannot
change the executable extension configuration, you may wish to change the
executable extension to .cgi, since many hosts have this extension
preconfigured (in this case you will also need to change the named path to
the script in the form).
Hopefully this will work. If it doesn't, then there is a problem with the
configuration. Let us know what platform and webserver you are using, and
whether you have access to the configuration file.
Good luck!
--Scott
[6/13] from: rchristiansen:pop:isdfa:sei-it at: 30-Jan-2001 17:09
This function doesn't work with GET on my system...
> retrieve-user-data: func [] [
> return decode-cgi
<<quoted lines omitted: 11>>
> ]
> ]
My system is as follows:
Apache/1.3.14 (Unix) mod_bwlimited/0.8 mod_log_bytes/0.2 PHP/4.0.4 mod_perl/1.24_01 mod_frontpage/3.0.4.3
mod_ssl/2.7.1 OpenSSL/0.9.5 on Linux
The function I use works with GET, but not with POST
retrieve-user-data: func [] [
return make object! decode-cgi
either system/options/cgi/request-method = "POST" [
input
][
system/options/cgi/query-string
]
]
I'm not the sysadmin. Suggestions?
[7/13] from: gjones05:mail:orion at: 30-Jan-2001 18:09
Ryan,
My version seems to work fine with GET and POST. I can't get your version
to work for GET and POST. When I remove the "make object!" phrase (making
it almost equivalent to Elan's), it works for get, but not post. Elan says
he uses his version for post also.
Then I started thinking that maybe it's a "version thing." I have been
using
REBOL/Core 2.3.0.3.1 for utilities and CGI. I tried using my version with
REBOL/View 0.10.38.3.1, and it worked for both GET and POST. Elan's version
also works for both GET and POST under REBOL/View 0.10.38.3.1. Remember
that this is on Windows 98.
Which version of REBOL are you using?
Here's to hopin' we're closing in.
-Scott
[8/13] from: gjones05:mail:orion at: 30-Jan-2001 18:34
Ryan,
I looked back at your original post and then remembered that you said you
were using the recommendation from the "Official User's Guide". Elan, who
happens to know one of the people who wrote the book VERY WELL <grin> is
using a modified version. He has left out the "make object!" phrase. Sorry
that I forgot about that. If the problem isn't a "version thing," then
perhaps Elan can explain why the change. I've not yet read the book (but
plan to soon), so I can't look it up.
-Scott
[9/13] from: rebol:techscribe at: 30-Jan-2001 21:39
Hi Ryan,
> My system is as follows:
> Apache/1.3.14 (Unix) mod_bwlimited/0.8 mod_log_bytes/0.2 PHP/4.0.4 mod_perl/1.24_01
mod_frontpage/3.0.4.3 mod_ssl/2.7.1 OpenSSL/0.9.5 on Linux
<<quoted lines omitted: 7>>
> ]
> ]
Using POST:
What exactly happens, if anything?
Have you tried replacing this function simply by
input
?
Could you send me a dump of what input returns? I.e. replace the above
line by
write %dump.txt mold input
TIA,
Elan
[10/13] from: rebol:techscribe at: 30-Jan-2001 21:34
Hi GS Jones
[...]
> left out the "make object!" phrase.
[...]
I didn't do that intentionally. I just happened to implement it that way
when I wrote the code for this Website.
Elan
[11/13] from: gjones05:mail:orion at: 31-Jan-2001 3:31
No problem, Elan, and I certainly didn't mean to imply anything negative.
Being new to the language, I just was "wondering out loud" that perhaps a
change in the version of REBOL required a change in the method. Through no
one's fault but my own, I am unclear why a "make object!" is needed.
Obviously, your site's version works both on your system and mine (at least
when I am using /View), but not on Ryan's. And Ryan says that his works
with the "make object!" phrase left in, but only with GET. When I use his
version, all I get is "?object?" printed for the data. As I have said to
Carl R., I probably shouldn't be pitching my two pennies in because I am
still a novice with REBOL. But I like mysteries and solving them helps me
learn the language more quickly.
Thanks for your input.
--- Scott (The "S" in GS Jones)
[12/13] from: rebol:techscribe at: 31-Jan-2001 10:36
Hi GS Jones,
I didn't read your message as containing anything negative.
In the version I'm using on the Website I use the make object! in the
calling function instead of in the retrieve-user-data function. That's
incidental.
The reason for make object! is:
decode-cgi returns a block that contains set-word! value pairs:
[name: "some-name" phone: "some-phone"]
To conveniently retrieve the values by using a path notation,
result/name result/phone I use the block returned by decode-cgi to
construct an object:
result: make object! decode-cgi input
If I were to simply say
result: decode-cgi input
then I wouldn't be able to access the values in the block using the path
notation in combination with the names: result/name wouldn't work
because in the block name appears as name:
result/name: wouldn't work because upon parsing a set-word as the last
element of a path REBOL expects that you are changing the value
following the word name and I would get an error reporting that the
value being assigned to result/name: is missing.
The one option would be to reduce the block returned by decode-cgi. Then
name and phone will become global words that are associated with their
respective values. I prefer to work with words that are local to the
object's context to avoic conflicts with other words that may be in use.
Hope this helps,
Elan
GS Jones wrote:
[13/13] from: rchristiansen:pop:isdfa:sei-it at: 30-Jan-2001 11:22
I'm still lost on how to use POST to create an object! containing the
values submitted in a form. The following function creates a string!
value called 'data, correct?
retrieve-user-data: func [] [
either system/options/cgi/request-method = "POST" [
data: make string! 2002
read-io system/ports/input data 2000
][
cgi: make object! decode-cgi-query
system/options/cgi/query-string
]
]
The /Core user's guide says "a good format for POST data is to use
a REBOL dialect and create a simple parser. The POST data can be
loaded and parsed as a block."
Why isn't there a built-in function for parsing POST data into an
object? Am I missing something?
-Ryan
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted