2015-01-21 53 views
1

现在用下面的链接传递自定义标题: -使用browsermob代理

https://github.com/jarib/browsermob-proxy-rb 

我已经尝试过这种通过自定义标题

require 'selenium/webdriver' 
require 'browsermob/proxy' 

server = BrowserMob::Proxy::Server.new("/path/to/downloads/browsermob-proxy/bin/browsermob-proxy") #=> #<BrowserMob::Proxy::Server:0x000001022c6ea8 ...> 
server.start 

proxy = server.create_proxy #=> 

proxy.headers({'test'=> 1}) 

但它会引发错误象下面这样: -

RestClient::InternalServerError: 500 Internal Server Error 
    from /home/karunakaran/.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!' 
    from /home/karunakaran/.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in `process_result' 
    from /home/karunakaran/.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/request.rb:178:in `block in transmit' 
    from /home/karunakaran/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:852:in `start' 
    from /home/karunakaran/.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit' 
    from /home/karunakaran/.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute' 
    from /home/karunakaran/.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute' 
    from /home/karunakaran/.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient/resource.rb:67:in `post' 
    from /home/karunakaran/.rvm/gems/[email protected]/gems/browsermob-proxy-0.2.0/lib/browsermob/proxy/client.rb:121:in `header' 
    from (irb):45 

如何通过使用browsermob代理请求传递自定义标题?

回答

0

您是否更改了示例代码的路径?在您粘贴代码,您有:

server = BrowserMob::Proxy::Server.new("/path/to/downloads/browsermob-proxy/bin/browsermob-proxy")

的/路径/到/ ...部分应该指向实际browsermob代理可执行文件。

+0

我只给了browsermob-proxy可执行文件。它的工作没有标题。我怎样才能通过标题。 – karan 2015-01-22 05:20:56

0

我已经通过标题键和值作为一个字符串,如下所示,它的作品。

require 'selenium/webdriver' 
require 'browsermob/proxy' 

server = BrowserMob::Proxy::Server.new("/path/to/downloads/browsermob-proxy/bin/browsermob-proxy") #=> #<BrowserMob::Proxy::Server:0x000001022c6ea8 ...> 
server.start 

proxy = server.create_proxy #=> 

proxy.headers({"test"=> "1"}) 
相关问题