From: "AleiPhoenix (A.K.A Areverie)" Date: 2012-12-16T23:53:14+09:00 Subject: net/http post request with nested hash data ? --bcaec54b4aa054303204d0f96cec Content-Type: text/plain; charset=UTF-8 Hi, I'm currently working on a script doing login function with a website. The login action requires a hash-like parameters as login[account] = "foobar@example.com" login[passwd] = "whatever" setting params in net/http like require "net/http" require "net/https" https = Net::HTTP.new("passport.115.com", 443) https.use_ssl = true req = Net::HTTP::Post.new("/?ac=login") req["login[account]"] = "foobar@example.com" req["login[passwd]"] = "whatever" res = https.request(req) p res.to_hash won't work, looks like the params weren't passed properly. and with req.set_form_data({"login" => {"account" => "foobar@example.com", "login" => "passwd"}}) has no luck either. but with req.set_form_data({"login[account]" => "foobar@example.com", "login[passwd]" => "whatever"}) doing the job. Any ideas? Thanks -- Silence is golden. twitter: @areverie wikipedia: AleiPhoenix blog: weblog.areverie.org wiki: wiki.areverie.org --bcaec54b4aa054303204d0f96cec Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi,=C2=A0

I'm currently working on a script doing lo= gin function with a website.

The login action requ= ires a hash-like parameters as

login[account] =3D "foobar@example.com"
login[passwd] =3D "whatever= "

setting params in net/http like=C2= =A0

req= uire "net/http"
require "net/https"

= https =3D Net::HTTP.new("passport.115.com", 443)
https.use_ssl =3D true
req =3D Net::HTTP::Post.new(&= quot;/?ac=3Dlogin")
req["login[account]"] =3D "foobar@example.com"
req["login[passwd]"] = =3D "whatever"
res =3D https.request(req)

p res.to_hash

won't work, looks like the params were= n't passed properly.

and with

req.set_form_data({"l= ogin" =3D> {"account" =3D> "foobar@example.com", "login" =3D> &q= uot;passwd"}})

has no luck either.


=

but with

req.set_form_data({"login[account]" =3D>= ; "foobar@example.com",= "login[passwd]" =3D> "whatever"})

doing the job.

Any ideas= ?

Thanks

--
Si= lence is golden.

twitter: @areverie
wikipedia: AleiPhoenix
blog: weblog.areve= rie.org
wiki: wiki.areverie.= org


--bcaec54b4aa054303204d0f96cec--