L
Lloyd Zusman
I'm using Net::HTTP to do a POST operation, but the query string I send
with variable settings seems to be ignored. Can anyone tell me what I
might be doing wrong?
require "net/http"
Net::HTTP.version_1_2
Net::HTTP.start('www.myhost.tld', 80) {
|http|
response = http.post('/test/showvars.php', 'foo=bar&ok=quack')
puts response.body()
}
When I run this, none of the variables show up as having been set.
However, if I send these variables to the script via a POST operation by
submitting them from a web page inside of a form like the one below,
I indeed see them as having been set:
<form action="http://www.myhost.tld/test/showvars.php" method="post">
<input type="hidden" name="foo" value="bar">
<input type="hidden" name="ok" value="quack">
<input type="submit" name="Submit" value="Submit">
</form>
Also, this has nothing to do with the /test/showvars.php script itself,
as I see the same results with any and all CGI's and servlets that I
invoke via http.post operations.
If I use the 1.1 version, I have the same problem with the POST:
require "net/http"
Net::HTTP.version_1_1
Net::HTTP.start('www.myhost.tld', 80) {
|http|
response, body = http.post('/test/showvars.php', 'foo=bar&ok=quack')
puts body
}
However, when I run this as a "GET", the variables get set fine:
require "net/http"
Net::HTTP.start('www.myhost.tld', 80) {
|http|
response = http.get('/test/showvars.php?foo=bar&ok=quack')
puts response.body()
}
I assume that I must be doing something wrong with the http.post
operation, but I can't figure out what that might be, since what I have
done seems to follow the Net::HTTP documentation.
Any ideas?
Oh, I almost forgot this:
% ruby --version
ruby 1.9.0 (2004-08-03) [i386-freebsd4.0]
% uname -sr
FreeBSD 4.0-STABLE
... and here's the showvars.php script:
<?php
$result = '';
if (isset($HTTP_POST_VARS)) {
$result .= "HTTP_POST_VARS:\n";
while (list($key, $val) = each($HTTP_POST_VARS)) {
$result .= " $key=$val\n";
}
}
if (isset($HTTP_GET_VARS)) {
$result .= "HTTP_GET_VARS:\n";
while (list($key, $val) = each($HTTP_GET_VARS)) {
$result .= " $key=$val\n";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<title>Show variables</title>
</head>
<body>
<b><pre>
<?php echo $result ?>
</pre></b>
</body>
</html>
Thanks in advance.
with variable settings seems to be ignored. Can anyone tell me what I
might be doing wrong?
require "net/http"
Net::HTTP.version_1_2
Net::HTTP.start('www.myhost.tld', 80) {
|http|
response = http.post('/test/showvars.php', 'foo=bar&ok=quack')
puts response.body()
}
When I run this, none of the variables show up as having been set.
However, if I send these variables to the script via a POST operation by
submitting them from a web page inside of a form like the one below,
I indeed see them as having been set:
<form action="http://www.myhost.tld/test/showvars.php" method="post">
<input type="hidden" name="foo" value="bar">
<input type="hidden" name="ok" value="quack">
<input type="submit" name="Submit" value="Submit">
</form>
Also, this has nothing to do with the /test/showvars.php script itself,
as I see the same results with any and all CGI's and servlets that I
invoke via http.post operations.
If I use the 1.1 version, I have the same problem with the POST:
require "net/http"
Net::HTTP.version_1_1
Net::HTTP.start('www.myhost.tld', 80) {
|http|
response, body = http.post('/test/showvars.php', 'foo=bar&ok=quack')
puts body
}
However, when I run this as a "GET", the variables get set fine:
require "net/http"
Net::HTTP.start('www.myhost.tld', 80) {
|http|
response = http.get('/test/showvars.php?foo=bar&ok=quack')
puts response.body()
}
I assume that I must be doing something wrong with the http.post
operation, but I can't figure out what that might be, since what I have
done seems to follow the Net::HTTP documentation.
Any ideas?
Oh, I almost forgot this:
% ruby --version
ruby 1.9.0 (2004-08-03) [i386-freebsd4.0]
% uname -sr
FreeBSD 4.0-STABLE
... and here's the showvars.php script:
<?php
$result = '';
if (isset($HTTP_POST_VARS)) {
$result .= "HTTP_POST_VARS:\n";
while (list($key, $val) = each($HTTP_POST_VARS)) {
$result .= " $key=$val\n";
}
}
if (isset($HTTP_GET_VARS)) {
$result .= "HTTP_GET_VARS:\n";
while (list($key, $val) = each($HTTP_GET_VARS)) {
$result .= " $key=$val\n";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<title>Show variables</title>
</head>
<body>
<b><pre>
<?php echo $result ?>
</pre></b>
</body>
</html>
Thanks in advance.