Question

I am doing an HTTP GET request but need to be able to add the port as it is not 80. Here is my code:

response = Net::HTTP.get(URI.parse("http://#{@hs_host}/dir/testpage.asp?event=#{CGI::escape(event_name)}"))

Which works perfect when the server is on port 80. What if the server is on port 85? Normally I would add :85 after the host but that seems to error.

Was it helpful?

Solution

uri = URI.parse(http://#{@hs_host}/dir/testpage.asp?event=#{CGI::escape(event_name)}")
uri.port = 8080

Or even:

uri = URI.parse(http://#{@hs_host}:8080/dir/testpage.asp?event=#{CGI::escape(event_name)}")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top