0

I'm trying to make a simple HTTP request via Ruby. However, I'm having trouble as the call to request does not return and blocks. I've tried the same request with Postman and it returns appropriately.

Here's my code:

1     uri = URI(TEST_URI) # test URL 
2     request = Net::HTTP::Get.new uri
3     request['Authorization'] = AUTHORIZATION # Contains Bearer <auth token>
4     http = Net::HTTP.new(uri.host, uri.port)
5     response = http.request(request)

Code execution stops at line 5 and does not continue. It seems as though the request is not returning. However, when I do a simple call to Net::HTTP.get_response(uri) without the correct Authorization, it returns appropriately, although obviously with an error. Again, the same request in Postman with the Authorization returns correctly.

Any help would be much appreciated!

elonybear
  • 41
  • 3

1 Answers1

2

It was an https link so it required an ssl connection. This was solved by including :use_ssl => true in the call to start.

Net::HTTP.start(uri.host, uri.port, :use_ssl => true)

which can also be found here: HTTPS request using Net::HTTP's block form -- is it possible?.

elonybear
  • 41
  • 3