【问题标题】:Replace BASH curl with Ruby equivalent将 BASH curl 替换为 Ruby 等效项
【发布时间】:2015-01-26 15:04:03
【问题描述】:

我正在尝试将我的 ruby​​ 中的 shell curl 替换为更原生的东西,例如“open-uri”,但失败并得到:“需要 401 授权”

我正在尝试替换这个:

status = system("curl -Is -w '%{http_code}\\n' --digest -u #{usr}:#{psw} https://#{source}/ -o /dev/null")

有了这个:

require 'open-uri'

status = open("https://#{source}/", :http_basic_authentication=>[usr, psw])

但仍然收到 401。知道吗? 谢谢

【问题讨论】:

    标签: ruby bash shell curl open-uri


    【解决方案1】:

    如果您点击任何重定向,this could be your problem:

    if redirect
      ...
      if options.include? :http_basic_authentication
        # send authentication only for the URI directly specified.
        options = options.dup
        options.delete :http_basic_authentication
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      • 2020-07-29
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      相关资源
      最近更新 更多