HTTParty and authorization via token

olimart picture olimart · May 12, 2014 · Viewed 13k times · Source

Somehow HTTParty returns 401 where CURL works fine. Not sure how to pass token in headers.

Working (200):

curl http://localhost:3020/api/products -H 'Authorization: Token token="111"'

Not working (401):

HTTParty.get('http://localhost:3020/api/products', headers: {"Authorization: Token token" => '111'})

I have tried with just "Authorization" => '111'and "token" => '111' but same result.

Answer

olimart picture olimart · May 20, 2014

Managed to get it working as follows.

HTTParty.get("http://localhost:3020/api/products", headers: {"Authorization" => "Token token=\"111\""})