Search code examples
ruby-on-railsrubyhttpartyopen-uri

HttpParty Proxy ip address usage


So i have a call to an api, Looks like this (url removed for safety yada yada)

apicall = HTTParty.get(URI.encode('URL HERE'), headers: {"Authorization" => "Bearer apikey"}).parsed_response

Now what i'm wanting is to use my proxy ip address to access the web page. Would you be willing to point me in the right direction to do this?

I've aware how to do this in open-uri but not sure if its possibe to do a get request with a this gem.

Thanks Sam


Solution

  • This should work.

    apicall = HTTParty.get(
      'URL HERE',
      http_proxyaddr:'PROXY IP HERE',
      http_proxyport: 'PROXY PORT HERE',
      http_proxyuser: 'PROXY USERNAME HERE',
      http_proxypass: 'PROXY PASSWORD HERE',
      headers: {"Authorization" => "Bearer apikey"}
    ).parsed_response
    

    Skip the http_proxy**** keys that you don't have values for. Everything you need to better understand what you can implement in HTTParty can be found here: HTTParty Github