0

次のリンクを使用しています:-

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/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/request.rb:230:in `process_result'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/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/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/request.rb:172:in `transmit'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/rest-client-1.6.7/lib/restclient/resource.rb:67:in `post'
    from /home/karunakaran/.rvm/gems/ruby-2.0.0-p247@pubm-qa/gems/browsermob-proxy-0.2.0/lib/browsermob/proxy/client.rb:121:in `header'
    from (irb):45

リクエストにbrowsermobプロキシを使用してカスタムヘッダーを渡すにはどうすればよいですか?

4

2 に答える 2

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"})
于 2015-01-27T06:04:07.490 に答える
0

サンプル コードのパスを変更しましたか? 貼り付けたコードには、次のものがあります。

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

/path/to/... 部分は、実際の browsermob-proxy 実行可能ファイルを指す必要があります。

于 2015-01-22T05:15:15.277 に答える