From: Felipe Contreras Date: 2007-04-25T17:25:17+09:00 Subject: Re: URL Splitting Hi, On 4/25/07, Mohamed Hussain wrote: > Hi Dude > Thank you for your reply > > Actually > i have one table called "urls" > > id url params > > 1 http://www.mob.com/add.asp username;password; > 2 http://www.zad.com/add.asp username;password;code; > 3 http://www.mob.com/add.asp username; > > > These are my table records > > I want to get these url and parameters dynamically depending upon id > > after i got the value > i will post the url by Net::HTTP.post_form() method > > i can get the record from table but i cannot post the url dynamically > i want to post the url in a single block. > > the username ,password and code are set dynamically > > i will call only one function like > g.send(1,user,pass) > g.send(2,user,pass,code) > g.send(3,user) > > these three function should call single method,on that method ,we should > post the url > > this is my problem > can anybody tell me the solution? This is still not clear. Are you going to use post_form like this: Net::HTTP.post_form(URI.parse('http://www.url.com'), { "user" => "hussain", "pass" => "hussain" }) Or: Net::HTTP.post_form(URI.parse('http://www.url.com?user=hussain&pass=hussain')) Besides, if you are going to fetch the parameters dynamically (I'm not sure what you mean by that) from the database, then shouldn't the g.send function receive only the id? So it should be either g.send(1) or g.send(url, user, pass) Anyway, check this code: require 'uri' def send(id, user, pass = nil, code = nil) params = {} params["user"] = user params["pass"] = pass if pass params["code"] = code if code query = params.map { |k,v| "%s=%s" % [URI.encode(k), URI.encode(v)] }.join("&") url = URI.parse("http://www.url.com") url.query = query p url.to_s end send(1, "foo", "bar") send(2, "foo", "bar", "300") send(3, "foo") -- Felipe Contreras