How to invoke HTTP POST method over SSL in ruby? -


so here's request using curl:

curl -xpost -h content-type:application/json -d "{\"credentials\":{\"username\":\"username\",\"key\":\"key\"}}" https://auth.api.rackspacecloud.com/v1.1/auth 

i've been trying make same request using ruby, can't seem work.

i tried couple of libraries also, can't work. here's have far:

uri = uri.parse("https://auth.api.rackspacecloud.com") http = net::http.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = openssl::ssl::verify_none request = net::http::post.new("/v1.1/auth") request.set_form_data({'credentials' => {'username' => 'username', 'key' => 'key'}}) response = http.request(request) 

i 415 unsupported media type error.

you close, not quite there. try instead:

uri = uri.parse("https://auth.api.rackspacecloud.com") http = net::http.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = openssl::ssl::verify_none request = net::http::post.new("/v1.1/auth") request.add_field('content-type', 'application/json') request.body = {'credentials' => {'username' => 'username', 'key' => 'key'}} response = http.request(request) 

this set content-type header post json in body, rather in form data code had it. sample credentials, still fails, suspect should work real data in there.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -