Gem Faraday: HTTP 验证问题?

michael_roshen · November 06, 2013 · Last by michael_roshen replied at November 06, 2013 · 3005 hits
$yun_cas = Faraday.new(:url =>YUN_CAS_URL) do |builder|
  builder.use Faraday::Request::UrlEncoded
  builder.use Faraday::Adapter::NetHttp
end

 response = $glodon_yun_cas.get do |req|
    req.url "/validate?ticket=#{params[:ticket]}&service=#{service_key}"
 end

发送这个 get 请求后,报错:An Authentication object was not found,不知道咋搞的,呼救!

HTTP Status 401 - An Authentication object was not found in the SecurityContext


type Status report

message An Authentication object was not found in the SecurityContext

description This request requires HTTP authentication.


Apache Tomcat/6.0.36

401 授权失败的错误

#2 楼 @michael_roshen 然后你就查啊是哪里授权失败了啊

#3 楼 @neverlandxy_naix 找到原因了,要在 header 里加 Authorization

response = $yun_cas.get do |req|
      req.url(url)
      req.headers['Authorization'] = basic_auth.gsub("\n","")
    end
You need to Sign in before reply, if you don't have an account, please Sign up first.