如何使用RestClient Ruby gem发送代理用户名和密码

问题描述

根据我们可以添加代理的文档,我正在使用RestClient gem作为发布请求,但是在我的情况下,代理URL本身具有身份验证,如何使用Restclient Gem来实现

RestClient.proxy = "someurl"
RestClient.proxy_user_name = ??
RestClient.proxy_password = ??

request = RestClient::Request.new(
    :method => :post,:url => 'some_url',:user => '123',:password => '123',:payload => {
        :multipart => true,:file => File.new("somepath",'rb')
   }
)
response = request.execute

解决方法

可以像这样使用RestClient::Request.execute

RestClient::Request.execute(
  method: :post,url: 'some_url',proxy: 'https://username:password@proxy_url:proxy_port' # will be parsed with URI.parse
)

在此处检查文档:rest-client