title: HTTP request works in Postman but not in Ruby (502 error)
body: <p>I'm quite new to Ruby but have to debug a Ruby code that I did not write.</p>
  
  <p>In the Ruby code, an HTTP request is made. After a bit of logging, I found out that the response object shows a 502 error. When I try the exact same request in Postman, I get the expected successful response :</p>
  
  <p><a href="https://i.stack.imgur.com/LC5aj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LC5aj.png" alt="enter image description here"></a></p>
  
  <p>I even tried to literally copy/past Postman's generated Ruby snippet, and it still gives me a 502 error when fired from the Ruby code.</p>
  
  <p>Here is the part responsible for the query (the request method, post part) :</p>
  
  <pre class="lang-rb prettyprint-override"><code>class PatentApi
    # Patent analysis API wrapper
  
    require 'uri'
    require 'net/http'
  
    DEFAULT_ENDPOINT = configatron.patent_api.endpoint.freeze
  
    # POST /api/v1/graph
    def post_complete_patent_graph(data)
      response = post('graph', data.to_json)
      response
    end
  
    # Send as POST request
    def post(path, options = {})
      request(:post, path, options)
    end
  
    # Build the request and return response
    def request(method, path, options)
      url = URI.parse(DEFAULT_ENDPOINT + path)
      Rails.logger.info (url.inspect) # The url looks ok in the logs !
      params = options # After logging, this value is ok
      case method
        when :get
          url.query = URI.encode_www_form(params)
          http = Net::HTTP.new(url.host, url.port)
          request = Net::HTTP::Get.new(url.request_uri)
          request["Accept"] = 'application/json'
          request["Content-Type"] = 'application/json'
          response = http.request(request)
          return response
        when :post
          request = Net::HTTP::Post.new(url, 'Content-Type' =&gt; 'application/json')
          request.body = params
          response = Net::HTTP.start(url.host, url.port, :read_timeout =&gt; 320) do |http|
            http.request(request)
          end
          Rails.logger.info 'RESPONSE'
          Rails.logger.info (response.code) # 502 ! :(
          Rails.logger.info (response.message)
          Rails.logger.info 'END RESPONSE'
          return response
      end
    end
  end
  </code></pre>