HTTPARTy with a proxy server

I'm on a heroic line trying to access an API that requires my ip apps to be whitelisted. So, I used heroku proxy to get host / ip for api whitelist.

The quick test I installed to test the connection using HTTParty does not work.

class FakeRequest include HTTParty http_proxy 'XX.XXX.XX.XX', 80, 'user', 'pass' def set_defaults {:api_key=>"BLARG_BLARG", :login_name=>"user", :method => "do_something", :response_format => "json", :v => "1.0", :login_password=>"pass"} end def make_post HTTParty.post "https://test.com", :query => set_defaults end end 

Go: req = FakeRequest.new req.make_post

Returns an error message from the api informing that the source IP address is not included in the white list. I looked at the source IP address and did not use a proxy server. How can I make an HTTParty message using a proxy server and not my ISP-IP.

+6
source share
5 answers

This is the module I created for this:

 module ProximoParty PROXIMO = URI.parse(ENV['PROXIMO_URL']) def self.included(base) base.send(:include, HTTParty) base.http_proxy(PROXIMO.host, 80, PROXIMO.user, PROXIMO.password) end end 

This uses the PROXIMO URL as it is added to your heroku application when installing the addon. Therefore, you can drop this file into your application and include ProximoParty in your FakeRequest class instead of HTTParty, and it should just work.

It looks like my code does the same thing your code does, but as I understand it, you cannot manually transfer credentials for proximo.

I ran into a similar problem when it didn’t quite work for me right away. I believe the problem was that I was confused because there was a proxy protocol in the proxy URL, but that was only part of the URL username.

In any case, this may or may not help, but please let me know if this happens!

+3
source

As you configure HTTParty as an inclusion in your module, you need to call the HTTParty method through your class, therefore:

 def make_post self.class.post "https://test.com", :query => set_defaults end 
+1
source

HTTParty can use the proxy server address using the following proxy settings .

 [:+http_proxyaddr+:] Address of proxy server to use [:+http_proxyport+:] Port of proxy server to use. [:+http_proxyuser+:] User for proxy server authentication [:+http_proxypass+:] Password for proxy server authentication. 
+1
source

I think you need to call local httparty, for example:

 def make_post self.post "https://test.com", :query => set_defaults end 
0
source

I included the link because it includes lengthy configuration steps. But the link change point and the page become invalid. We used the squid proxy on ECI AMI and named it day.

0
source

Source: https://habr.com/ru/post/927043/


All Articles