Saurabh Shah Saurabh Shah - 1 year ago 70
Ruby Question

How to solve HTTP Temporary Redirect error in using 'net/http' in ruby?

This following code continuously gives me

error. I tried to look at Ruby - net/http - following redirects, but of no use.

require 'uri'
require 'net/http'
require 'json'
uri = URI.parse("")
https =, uri.port)
https.use_ssl = true
output = `travis token --org`
request =
request["Content-Type"] = 'application/json'
request["Accept"] = 'application/json'
request["Travis-API-Version"] = '3'
request["Authorization"] = 'token '+output
request.body = {'request' => {'branch' => 'master'}}.to_json
response = https.request(request)
puts response

PS: If I remove the output variable and just paste the command line output in
I get a success. Strange?

Answer Source

Have you checked where it redirects, and which other headers it returns?

Is it possible, that travis token --org includes a newline that you have to strip?

If that doesn't solve it, could you paste the response.inspect ?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download