Forum: Ruby post_form not posting to full url

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A00697fc31e1dc8077916f0c4696742c?d=identicon&s=25 Pat Goebel (putterson)
on 2007-06-30 07:17
I am using Net::HTTP.post_form to post this form information:
{ "form_action" => "pet.do_fight", "mcid" => "9", "level" => "30",
"type" => "fightmonster" }
to this url:
http://neo2.hotornot.com/facebook/pet/?fb_sig_in_i...
and while it should be posting to this url when I used a packet sniffer
(because it was not working) it showed me that it was posting only to
this url:
http://neo2.hotornot.com/facebook/pet/
it gives me a 404:
<style>
.msg404 {
  font-family:Arial,sans-serif;
  font-size:24px;
  text-align:center;
}
</style>
<div class="msg404">Sorry!  This page cannot be found</div>
as well as giving me:
#<Net::HTTPNotFound:0x2b65600>
...what am i doing wrong:
-------------------
require 'net/http'
require 'uri'
spooform = { "form_action" => "pet.do_fight", "mcid" => "9", "level" =>
"30", "type" => "fightmonster" }
fightit =
"http://neo2.hotornot.com/facebook/pet/?fb_sig_in_i...
responce = Net::HTTP.post_form(URI.parse(fightit),spooform)
puts responce
-------------------
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jano Svitok (Guest)
on 2007-07-01 00:49
(Received via mailing list)
On 6/30/07, Pat Goebel <putterson@gmail.com> wrote:
> <style>
> -------------------
> require 'net/http'
> require 'uri'
> spooform = { "form_action" => "pet.do_fight", "mcid" => "9", "level" =>
> "30", "type" => "fightmonster" }
> fightit =
> 
"http://neo2.hotornot.com/facebook/pet/?fb_sig_in_i...
> responce = Net::HTTP.post_form(URI.parse(fightit),spooform)
> puts responce

this source for  post_form (copied from ruby-doc.org):

def HTTP.post_form(url, params)
      req = Post.new(url.path)
      req.form_data = params
      req.basic_auth url.user, url.password if url.user
      new(url.host, url.port).start {|http|
        http.request(req)
      }
end

You can see that it doesn't send Uri#query.

Try either joining the GET parameters with POST ones, and send them
all as POST params, or use Http#post and specify the path and query
string.

uri = URI.parse('http://...')
i.e. Http.open(uri.host) do |http|
  response = http.post(uri.path + '?' + uri.query, <uri-encoded
spooform data as string>)
end

you'd need to find out how to encode the form data.

Disclaimer: It's 1AM here, I have not tested anything, so take these
as ideas to investigate...

J.
This topic is locked and can not be replied to.