[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

URL Splitting

Mohamed Hussain

4/21/2007 6:44:00 PM

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&passwo...
2) http://www.zad.com/list.asp?userna...
3) http://www.mob.com/add.asp?username=hussain&passwo...&code=xxx

I have stored this data "http://www.mob.com/add... 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

--
Posted via http://www.ruby-....

4 Answers

Felipe Contreras

4/24/2007 10:06:00 AM

0

Hi,

On 4/21/07, hussain <pshussain@gmail.com> wrote:
> 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&passwo...
> 2) http://www.zad.com/list.asp?userna...
> 3) http://www.mob.com/add.asp?username=hussain&passwo...&code=xxx
>
> I have stored this data "http://www.mob.com/add... 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?

--
Felipe Contreras

Mohamed Hussain

4/25/2007 3:59:00 AM

0

Hi Dude
Thank you for your reply

Actually
i have one table called "urls"

id url params

1 http://www.mob.c... username;password;
2 http://www.zad.c... username;password;code;
3 http://www.mob.c... 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






--
Posted via http://www.ruby-....

zswu

4/25/2007 7:25:00 AM

0

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?

On 4/25/07, Mohamed Hussain <pshussain@gmail.com> wrote:
> Hi Dude
> Thank you for your reply
>
> Actually
> i have one table called "urls"
>
> id url params
>
> 1 http://www.mob.c... username;password;
> 2 http://www.zad.c... username;password;code;
> 3 http://www.mob.c... 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
>
>
>
>
>
>
> --
> Posted via http://www.ruby-....
>
>


--
/***********************************/
Lets go With the float....
/***********************************/

Felipe Contreras

4/25/2007 8:25:00 AM

0

Hi,

On 4/25/07, Mohamed Hussain <pshussain@gmail.com> wrote:
> Hi Dude
> Thank you for your reply
>
> Actually
> i have one table called "urls"
>
> id url params
>
> 1 http://www.mob.c... username;password;
> 2 http://www.zad.c... username;password;code;
> 3 http://www.mob.c... 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.ur...), { "user" =>
"hussain", "pass" => "hussain" })

Or:

Net::HTTP.post_form(URI.parse('http://www.url.com?user=hussain&pass=hu...))

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...)
url.query = query

p url.to_s
end

send(1, "foo", "bar")
send(2, "foo", "bar", "300")
send(3, "foo")

--
Felipe Contreras