Faysal
Faysal

Reputation: 45

Get HTTP error RestClient::Unauthorized (401 Unauthorized): Using 'rest-client' gem in rails

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

Upvotes: 3

Views: 5805

Answers (1)

H6_
H6_

Reputation: 32808

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)

Upvotes: 3

Related Questions