如何配置Ruby Mechanize代理以通过Charles Web代理工作?

编程入门 行业动态 更新时间:2024-10-28 20:23:24
本文介绍了如何配置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上.假定服务器位于 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代理工作?

本文发布于:2023-06-05 21:06:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/527647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   Mechanize   Ruby   Web   Charles

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!