Why doesn't this work? (CGI)

That thought had crossed my mind, but the fact that the following worked:

<html><head></head><body>
<a href="test.rhtml?key=val">test key</a>
<%
    cgi = CGI.new
    puts cgi['key']
%>
</body></html>

when I clicked on the url made me beleive that I could mix and mash.

···

I don't know the internals of the CGI module well, but you're mixing a query string and a HTTP POST. Does it work if you change method=post to method="GET"?

I'm sure there's a way to get both the query string and the posted variables out, though you might need to do some manual parsing of the query string. In general though, you shouldn't be mixing query string arguments and POSTs.

Ben

_________________________________________________________________
From ‘will you?’ to ‘I do,’ MSN Life Events is your resource for Getting Married. http://lifeevents.msn.com/category.aspx?cid=married

Yes, you can absolutely mix and match POST and GET as long as your
argument parser knows the difference, which it appears cgi.rb does not.
Looking through it's source it seems like on a POST it doesn't check
the query args, only reading the post arguments.

This isn't hard to parse on your own if you have to, but it also looks
like you could get both sets of arguments this way, using a method in
cgi.rb to do the parsing, but telling it what to parse yourself:

query_args = CGI::parse( ENV['QUERY_STRING'] )
$stdin.binmode
post_args = CGI::parse( $stdin.read(Integer(ENV['CONTENT_LENGTH'])) or
'' )

···

On Thu, 24 Jun 2004 05:07:57 +0900, Orion Hunter wrote:

That thought had crossed my mind, but the fact that the following worked:

when I clicked on the url made me beleive that I could mix and mash.

--
Rando Christensen
eyez@illuzionz.org

Orion Hunter wrote:

That thought had crossed my mind, but the fact that the following worked:

<html><head></head><body>
<a href="test.rhtml?key=val">test key</a>
<%
   cgi = CGI.new
   puts cgi['key']
%>
</body></html>

when I clicked on the url made me beleive that I could mix and mash.

In that case, you're not mixing and matching. You're only doing a "GET" request. A "GET" request is what you do whenever you click on a link. Whenever you submit a form, you may be doing a "GET" request, or may be doing a "POST", it depends on what the "method" parameter of the form is.

To the web server, there's no difference between clicking on this link:

<a href="foo.rhtml?key=val">click here!!!!!</a>

And submitting this form:

<form action="foo.rhtml" method="GET">
<input type="hidden" name="key" value="val">
<input type="submit">
</form>

(Although I think if you set the value or the name of the submit button then you'll get a key/value pair for that too.)

Ben