我正在使用Ruby/Mechanize编写自动填写表格"应用程序.它几乎可以正常工作.
I'm writing an "automatically fill in the forms" app using Ruby / Mechanize. It almost works.
我可以使用出色的 Charles 网络代理来查看服务器与Firefox浏览器之间的交换.现在,我想使用Charles来查看服务器与我的应用程序之间的交换.
I can use the wonderful Charles web proxy to see the exchange between the server and my Firefox browser. Now I want to use Charles to see the exchange between the server and my app.
Charles代理位于端口8888上.假定服务器位于 my.host .不起作用的一件事是:
Charles proxies on port 8888. Assume that the server is at my.host. One thing that does NOT work is:
@agent ||= Mechanize.new do |agent| agent.set_proxy("my.host", 8888) end这将导致Net::HTTP::Persistent::Error:
...lib/net/http/persistent.rb:579:in `rescue in connection_for': connection refused: my.host:8888 (Net::HTTP::Persistent::Error)所以我给agent.set_proxy(host, ...)赋予了错误的主机参数,或者我没有正确配置Charles. (FWIW,我曾经能够做到这一点,但是自从那些宁静的日子以来,Mechanize和Charles都已经成熟了好几代了...)
So either I'm giving the wrong host argument to agent.set_proxy(host, ...), or I haven't configured Charles properly. (FWIW, I used to be able to do this, but both Mechanize and Charles have matured several generations since those halcyon days...)
有什么想法吗?
推荐答案Web代理通常不是通过只是端口来定义的,但通常是完整的主机名. Charles很可能安装在本地主机上.因此,以下调整可能对您有用:
A web proxy is not normally defined by just a port, but is usually a full host name. Charles is very likely installed on localhost. Therefore the following adjustment may work for you:
@agent ||= Mechanize.new do |agent| agent.set_proxy("localhost", 8888) end更多推荐
如何配置Ruby Mechanize代理以通过Charles Web代理工作?
发布评论