English 中文(简体)
救助废气机械工案
原标题:Save a file with ruby mechanize

我在法典方面有问题(这部法典可能会获得请求和复制;下载文件):

require  rubygems 
require  mechanize 
require  hpricot 

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

user = "xxx"
pass = "xxx"
auth_key = "xxx"
ip = "xxx"

agent = Mechanize.new
page = agent.get("https://#{ip}/cgi-bin/welcome.cgi")
form = page.forms.first
form.username = user
form.password = Digest::MD5.hexdigest(pass + auth_key)
page = agent.submit form

page = agent.get("https://#{ip}/cgi-bin/config.exp")
form = page.forms.first
agent.pluggable_parser.default = Mechanize::FileSaver
agent.post("https://#{ip}/cgi-bin/config.exp", {"submitstatus" => "1"})

我有这样的错误:

/var/lib/gems/1.8/gems/mechanize-2.4/lib/mechanize/http/agent.rb:291:in `fetch : 400 => Net::HTTPBadRequest for https://31.223.225.133/cgi-bin/config.exp -- unhandled response (Mechanize::ResponseCodeError)
 from /var/lib/gems/1.8/gems/mechanize-2.4/lib/mechanize.rb:407:in `get 
 from /home/lord/Dropbox/work/ruby/ruby_backup/backup.ru:22

How to simulate this wget request for downloading file:

 `wget --no-check-certificate --load-cookies cookie --post-data= submitstatus=1  
 --header= Host: 10.1.25.254  
 --header= User-Agent: Mozilla/5.0  
 --header= Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
 --header= Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3  
 --header= Accept-Encoding: gzip, deflate  
 --header= Connection: keep-alive  
 --header= Referer: https://10.1.25.254/sys_setting.htm  
 --header= Content-Type: application/x-www-form-urlencoded  
 --header= Content-Length: 14  
 https://$ip/cgi-bin/config.exp`

增 编

问题回答

如果你通过假肢或char等欺骗性代理来代理你的机械化和植被要求,你可以相互比较,从而更好地了解问题。

Have you tried Mechanize::Download?

此处为参考

使用 WW: 设法下载一个文件,不把文件装上一栏





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签