3

i have use the Ruby Gem rest-client for request on a url of a website. and i get the following error...

RestClient::Unauthorized (401 Unauthorized):
  app/controllers/api/v1/channels_controller.rb:199:in `streaming_link'

help me to fix it. my controller method is bellow

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
Faysal
  • 47
  • 1
  • 9

1 Answers1

3

I was also struggling with rest-client and a 401 until I recognised, that it was because of the digest authentication the service needed. Rest-Client currently did not support digest auth.

Instead I switched to httparty, which supports it and with this it worked. Maybe it's the same with your 401.

@auth = {:username => 'hashapp', :password => 'PlayFair00'}
options = { :digest_auth => @auth }
response = HTTParty.get('http://eboundservices.com/hash/hash_app.php?code=orientplay', options)
disco crazy
  • 31,313
  • 12
  • 80
  • 83