Gem Faraday: HTTP 验证问题?

michael_roshen · 2013年11月06日 · 最后由 michael_roshen 回复于 2013年11月06日 · 3005 次阅读
$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
需要 登录 后方可回复, 如果你还没有账号请 注册新账号