开发者

is there a way using Ruby's net/http to post form data to an http proxy?

I h开发者_如何学Cave a basic Squid server setup and I am trying to use Ruby's Net::HTTP::Proxy class to send a POST of form data to a specified HTTP endpoint.

I assumed I could do the following:

  Net::HTTP::Proxy(my_host, my_port).start(url.host) do |h|
    req = Net::HTTP::Post.new(url.path)
    req.form_data = { "xml" => xml }
    h.request(req)
  end

But, alas, proxy vs. non-proxied Net::HTTP classes don't seem to use the proxy IP Address. my remote service responds telling me that it received a request from the wrong IP address, ie: not the proxy. I am looking for a specific way to write the procedure, so that I can successfully send a form post via a proxy. Help? :)


Hah, turns out that is the right way to do it, my issue was actually with Squid and the API I was pushing to. Interesting tip related to this problem, if you are proxying with Squid proxy server, you probably want to add this server config option:

header_access X-Forwarded-For deny all

This will make sure that the proxy completely ignores any relation to the caller's IP address as far as the HTTP endpoint is concerned.


You may also want to look at the mechanize gem, based on Perl's WWW::Mechanize. If it's anything like the Perl one (and I'm led to believe it is), then it encapsulates much of the common mess that you're dealing with.

Ruby: http://mechanize.rubyforge.org/

Perl: http://search.cpan.org/dist/WWW-Mechanize/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜