Equivalent of cURL for Ruby?
Use OpenURI and
open("http://...", :http_basic_authentication=>[user, password])
accessing sites/pages/resources that require HTTP authentication. Ruby equivalent of this curl command
Using rest-client
RestClient.post 'localhost:9200/_bulk', File.new("filename.json", 'rb'), 'Content-type' => 'application/x-www-form-urlencoded'
not sure if rest-client
automatically set content-type
, just check without it. Ruby equivalent of curl with -H (header) switch
Here's an example how this can be accomplished with a standard library net/http:
require 'net/http'
url = '...'
uri = URI(url)
http = Net::HTTP.new(uri.host)
request = Net::HTTP::Get.new(uri.path)
request['authorization'] = %{Token token="#{password}", userID="#{user_id}"}
res = http.request(request)
Converting curl to ruby equivalent
I think you just need to serialise the ruby structure to JSON in the second param. The param should be the string to POST, not a Ruby struct.
I think this will work (only other possible problem I can see is whether you'll connect via https as the code is written):
data = {"channels": ['Giants'], "data": {alert: 'un mensaje '}}
puts Parse.post("/1/push", body: data.to_json)
. . . the JSON-like format in the Ruby data structure is not JSON, foo: "bar"
is just another Ruby (1.9+) way of saying:foo => "bar"
Equivalent Curl Request
Try this
curl -X POST -d "user[username]=fasfas&user[password]=fasfas&user[password_confirmation]=fasfas&user[email]=fasfas@fasfas.com" http://someurl.com/users
Related Topics
Rails: Before Process_Action Callback: Authenticate_User! Has Not Been Defined
How to Resize Image Only If Width Exceeds with Graphics/Image Magick
Combining Ruby on Rails and Backbone
Why Do Ruby People Say They Don't Need Interfaces
Error Installing Rdoc Documentation: Incompatible Encoding Regexp Match
How to Use Variable Arguments with Ruby's Optionparser
Fresh Ruby Gem from Bundler - Cannot Load My Version.Rb File
Calling Module Method into Another Module in Ruby
Ruby Trying to Grasp a New Notation. (Inject(: ) Vs Select(&:Even); Why One Has &)
How to Access Sinatra App on Host Machine with Vagrant Forwarded Ports
How to Get All Message History from Hipchat for a Room via The API
How Do Erlang Actors Differ from Oop Objects
Server Sent Events and Rails Streaming
Save PDF File Shown by Pdfkit Middleware
How to Use Omniauth to Make Authenticated Calls to Services
Can't Log into Active Admin. Any Way to Create an Admin User