如何配置Ruby Mechanize代理以通过Charles Web代理工作? [英] How do I configure a Ruby Mechanize agent to work through the Charles web proxy?

查看:99
本文介绍了如何配置Ruby Mechanize代理以通过Charles Web代理工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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上.假定服务器位于 https://my.host.com .不起作用的一件事是:

Charles proxies on port 8888. Assume that the server is at https://my.host.com. One thing that does NOT work is:

@agent ||= Mechanize.new do |agent|
  agent.set_proxy("my.host.com", 8888)
end

这将导致Net::HTTP::Persistent::Error:

...lib/net/http/persistent.rb:579:in `rescue in connection_for': connection refused: my.host.com: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代理工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆