我已经使用Ruby Gem rest-client
在网站的URL上请求。 我收到以下错误...
RestClient::Unauthorized (401 Unauthorized):
app/controllers/api/v1/channels_controller.rb:199:in `streaming_link'
帮我修复它。我的控制器方法是波纹管
def streaming_link
url = URI.encode("http://eboundservices.com/hash/hash_app.php?code=orientplay")
result = RestClient::Request.new({:user => "hashapp", :password => "PlayFair00",:method => :post, :url => url}).execute
return render :json =>{:success=>true,:result=>result}
end
我也在为 rest-client 和 401 而苦苦挣扎,直到我认识到这是因为服务需要的摘要式身份验证。Rest-Client 目前不支持摘要身份验证。
相反,我切换到支持它的httparty,并且它起作用了。也许你的 401 也是如此。
@auth = {:username => 'hashapp', :password => 'PlayFair00'}
options = { :digest_auth => @auth }
response = HTTParty.get('http://eboundservices.com/hash/hash_app.php?code=orientplay', options)