Reputation: 9216
I'm creating a post to send to a RESTful web service, my current code looks as such:
vReq = Net::HTTP::Post.new(uri.path)
vReq.body = postData
vReq.basic_auth('user', 'pass')
@printReq = vReq['basic_auth']
I am finding that the @printReq does not get assigned anything, and the headers, is not defined. Attempting to read any known header by name returns no results. It appears no header information is getting created when I do this. vReq.body
does in fact return the postData I've created. What am I missing that will create the headers correctly?
Upvotes: 0
Views: 395
Reputation: 34340
You might want to try something like this:
domain = 'example.com' path = '/api/action' http = Net::HTTP.new(domain) http.start do |http| req = Net::HTTP::Post.new(path) req.basic_auth 'user', 'pass' req.set_form_data(postData, ';') response = http.request(req) puts response.body # Get response body puts response.header["content-encoding"] # Get response header end
Upvotes: 1