Lloyd Zusman <ljz / asfast.com> writes:

> 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()
>   }

I figured out the answer.  I need to explicitly set the Content-Type to
"application/x-www-form-urlencoded":

   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',
                  { 'Content-Type' => 'application/x-www-form-urlencoded' })
     puts response.body()
   }

But shouldn't net/http do this for me when I'm calling the #post method
with a query string?  The documentation for Net::HTTP seems to imply
this, as it doesn't specify an explicit setting of Content-Type to
"application/x-www-form-urlencoded" in the example that it shows.

From the Net::HTTP documentation:

  Posting Form Data

      require 'net/http'
      Net::HTTP.start('some.www.server', 80) { |http|
          response = http.post('/cgi-bin/search.rb', 'query=ruby')
      }


-- 
 Lloyd Zusman
 ljz / asfast.com
 God bless you.