URL Splitting

H

hussain

Hai
I am new to Ruby
now i have one situation
that,I need to get the url from database dependding upon user id
i have stored the url in database and also stored the parameter keys in
database
but my problem is ,i can get the url and parameter from database, but i
want to post the url from ruby Net/http api.i am using
Net::HTTP.post_form() method to post the Url,but my question is ,if the
url having the same type of parameter then there is no problem,if the
Url is not having the same type of parameter then how can i post the Url
dynamically?

Example:

1) http://www.mob.com/add.asp?username=hussain&password=hussain
2) http://www.zad.com/list.asp?username=hussain
3) http://www.mob.com/add.asp?username=hussain&password=hussain&code=xxx

I have stored this data "http://www.mob.com/add.asp" in url field in DB
I have stored this data "username;password" in parameter field in DB
i want to post these three url dynamically from Ruby

can anybody tell me the answer?

Bye
By
P.S.Hussain
 
F

Felipe Contreras

Hi,

Hai
I am new to Ruby
now i have one situation
that,I need to get the url from database dependding upon user id
i have stored the url in database and also stored the parameter keys in
database
but my problem is ,i can get the url and parameter from database, but i
want to post the url from ruby Net/http api.i am using
Net::HTTP.post_form() method to post the Url,but my question is ,if the
url having the same type of parameter then there is no problem,if the
Url is not having the same type of parameter then how can i post the Url
dynamically?

Example:

1) http://www.mob.com/add.asp?username=hussain&password=hussain
2) http://www.zad.com/list.asp?username=hussain
3) http://www.mob.com/add.asp?username=hussain&password=hussain&code=xxx

I have stored this data "http://www.mob.com/add.asp" in url field in DB
I have stored this data "username;password" in parameter field in DB
i want to post these three url dynamically from Ruby

can anybody tell me the answer?

I don't understand what you want.

Can you please rephrase or give some concrete example?
 
M

Mohamed Hussain

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?


ok
Bye
By
P.S.Hussain
 
Z

zswu

class G
def send( url, user, pass, code = nil )
begin
str = Url.find( url ).url + '?username=' + user + '&password=' + pass.to_s
str += '&code=' + code.to_s if code
rescue => e
if e.is_kind_of RecordNotFoundError
...
end
end
end
end

Is this?
 
F

Felipe Contreras

Hi,

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")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top