Question

The syntax for NET:HTTP seems complicated and there are very minor things that might get missed.

However curl is much older and well documented.

Is there some documentation/blog-post etc where NET:HTTP equivalent constraints for curl are published ?

eg:

To make a https request use:

http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

How do I use curl flags like -u, -X, -H, -d in NET:HTTP ? Any resources would be helpful.

Thanks

P.S: Its not possible to use third party gems in the environment I am using.

Was it helpful?

Solution

-X controls the kind of request you're making. You control that by creating the request type you want, i.e.: Net::HTTP::Post (or Net::HTTP::Put, and so on).

-d sets the data, so, request.set_form_data({"key" => "value"}).

-u is for username (and password? i don't remember the specifics of -u with cURL), so, request.basic_auth("username", "password").

-H sets a header, so, request.add_field("header", "value")

I usually use this as a reference when I'm working with Net::HTTP and forget something (since its pretty easy to find on Google when I lose the link.)

PS: You can always install gems to a local directory and set a custom GEM_HOME and GEM_PATH instead of using the system-provided gem dirs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top