Reputation: 121
I am trying to make a http post using require 'net/http' here is my request
token_url = 'http://www.[url].com/oauth/token'
uri = URI(token_url)
req = Net::HTTP::Post.new(uri)
req.basic_auth ENV['OAUTH_ID'], ENV['OAUTH_PASSWORD']
req.set_form_data({ 'grant_type' => 'client_credentials' })
resp = Net::HTTP.new(uri.host, uri.port).start {|http| http.request(req) }
JSON.parse(resp.body)['access_token']
I keep getting this error: NoMethodError - undefined method 'empty?' for #<URI::HTTP:0x007fb2ed01bdf8>:
This happens on this line "req = Net::HTTP::Post.new(uri)
".
any ideas why?
Upvotes: 1
Views: 1018
Reputation: 121
Figured it out:
replace
req = Net::HTTP::Post.new(uri)
with
req = Net::HTTP::Post.new(uri.request_uri)
Upvotes: 2