From: Raul Parolari Date: 2007-12-28T05:03:33+09:00 Subject: Re: calling a ruby program from java script Pradeepta Swain wrote: > My task is to automate the web service.. > when someone opens the client's site and enters credentials and > clicks button , then ruby script will pick that information from the > fields and after validating redirects to a 3rd party . Pradeepta, it is not clear yet what the 'client site' (that I will call simply 'client' from now on) is: 1) is it the browser? (you mentioned 'calling from javascript' before). In this case, as far as I know, you cannot call a ruby program (resident in the same computer) from Javascript running in the browser. 2) is the 'client' a Gui tool that needs to invoke a program? depending on the platform you are in, there are many possibilities; from a rudimentary 'system' call (on Unix) to a socket-based communication (that would allow the ' 'ruby program' communicate the 'client site' information beyond success/failure). This would mean that the 'client' has to serialize the 'form' (with the user data), and transmit the information to the 'ruby program' using whatever IPC is available (and best for the purpose). Once we are inside the ruby program, you can use Net::HTTP. I don't have direct experience with it, but a quick look at the doc shows several ways to do a POST request; for example: url = URI.parse('...') req = Net::HTTP::Post.new(url.path) req.basic_auth(..) req.set_form_data({'user_name'=>'..', 'password'=>'..'}, ';') # then the request is sent, etc In any case, things seem simple; the original 'form' is translated into a hash of key-values (as usual). Of course you have to use the same names expected by server; but there is no problem in how to 'transmit the form' (that seems a concern of yours). [You can also look at another library: rest-open-uri (a Ruby gem), that operates at a higher level than net/http; but this is not your problem right now]. The point to solve is how the 'client' serializes the form (again, not a problem for a form so simple, whatever language you are using in the GUI client) and in how you choose to do the IPC. However the fact that you are so concerned with 'how to process the form' makes me think that something fundamental is still not clear yet in all this. I hope this helped however Raul -- Posted via http://www.ruby-forum.com/.