2

How do you do a Remote HTTP Post (request) in ruby?

2 Answers 2

9

With Net::HTTP. Correct but non-working example (because Google only supports GET — sorry, I couldn't think of any open POST forms off the top of my head):

require 'net/http'
require 'uri'

result = Net::HTTP.post_form(URI.parse("http://google.com/search"), {"q" => "Rick Astley"})

docs

Sign up to request clarification or add additional context in comments.

2 Comments

You are posting a form to a search which takes get parameters. Google will return you an error.
That's what I said. Google actually requires GET parameters, but I couldn't think of any good examples of commonly used POST forms off the top of my head. I think it pretty clearly illustrates how you do a POST, though.
2

If the server conforms to REST you should take a look at either rest-client or ActiveResource.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.