Question

I'm using rest-client (worst name ever for a google search) to query an API.

Here is my code :

def self.list
    request="http://#{URI.escape @@user}:#{URI.escape @@password}@webservicedomain.com/params/params/"
    Rails.logger.debug request
    response = RestClient.get request
    response.code
  end

It give me the request i pass to Rest Client and then a 406 error :

MyService.list
http://username:password@webservicedomain.com/params/params/
RestClient::NotAcceptable: 406 Not Acceptable

Strange thing is, if i use the request in my browser it works fine. I think it may have to do with the fact this webservice only answer with HTML, but i'm not sure how to change that and test client does not really have a Doc.

Something great for starter, would be to see the header of the request rest-client sent.

How can i make it work ?

UPDATE

the exception thrown by rest-client after inspection contain the following error :

Invalid mime-type "*/*; q=0.5"
Was it helpful?

Solution

RestClient docs (to the extent that they exist) are here. I don't think your problem is that the API is responding with HTML. My guess would be that RestClient doesn't understand the way you're providing your access credentials. Try using request headers for that instead?

Personally, I prefer the Faraday gem for interacting with APIs - it's a lot better about showing you what's actually going on, especially when there's an error.

OTHER TIPS

Though this is late, just FYI, this can be fixed by specifying the accept header in the request. The default value seems to be "/; q=0.5, application/xml". So you can fix it by setting the value of the header to what you're expecting

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top