json - Stuck with HTTP GET authentication in Ruby -


i trying write short script http authentication using request

this makes request.

    def try_login(u, p)       path1 = '/index.php'       path2 = '?uuser=#{myuser}&ppass=#{mypass}'       r = send_request_raw({         'uri' => "#{path1}#{path2}",         'method' => 'get'       })     ...continued... 

but code not work because error says:

undefined local variable or method `myuser'

--> trying send 1 (1) request login parameters, , app responds specific data. , not know how put placeholders user , pass in request.

...

next, checking http response. response comes in json mime this:

success response

{"param1":1,"param2"="auth success","menu":0,"userdesc":"my user","user":"uuser","pass":"ppass","check":"success"} 

fail response

{"param1":-1,"param2"="auth fail","check":"fail"} 

--> how can check response body kind of data.

i have been trying day now, stuck totally. please advice.

edit: not understand why 1 down voted question saying little no research on part. until before yesterday morning, had absolutely 0 idea ruby code & working it. , spent numerous hours looking @ many different examples, making script , testing out. when still didn't work, asked question here. please, if still want down vote, please, @ least share pointers solve well.

def try_login(u, p)   path1 = '/index.php'   path2 = '?uuser=#{myuser}&ppass=#{mypass}'   r = send_request_raw({     'uri' => "#{path1}#{path2}",     'method' => 'get'   }) ...continued... 

should be:

def try_login(u, p)   path1 = '/index.php'   path2 = "?uuser=#{u}&ppass=#{p}"   r = send_request_raw({     'uri' => "#{path1}#{path2}",     'method' => 'get'   }) ...continued... 

for parsing json in ruby, recommend take @ this answer question.

edit: reason try_login(u, p) isn't working expect because ruby not string interpolation single quoted (') strings. additionally, myuser , mypass not appear correct variables.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -