Skip to content

Instantly share code, notes, and snippets.

@Marahin
Last active October 27, 2015 14:08
Show Gist options
  • Save Marahin/436861c3708ed439e4a1 to your computer and use it in GitHub Desktop.
Save Marahin/436861c3708ed439e4a1 to your computer and use it in GitHub Desktop.
Hello,
I'm trying to download some API results from
http://steamcommunity.com/market/pricehistory/?country=US&currency=3&appid=730&market_hash_name=Operation%20Phoenix%20Weapon%20Case
the link opened in browser works just fine, however when I tried to open it with open-uri (open(link).read()) it threw a [] 400.
I was adviced to take a look into headers I send, and so I have found some in Chrome devtools. I now get a response, however it's unreadable, and I suspect it might be due to the encoding / gzip inflation? Not sure, I'm really a rookie.
Help will be greatly appreciated. The code I'm using is shown below. :)
require 'net/http'
require 'uri'
require 'right_http_connection'
uri = URI("http://steamcommunity.com/market/pricehistory/?country=US&currency=3&appid=730&market_hash_name=Operation%20Phoenix%20Weapon%20Case")
headers = {
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'DNT' => '1',
'Accept-Encoding' => 'gzip, deflate, sdch',
'Accept-Language' => 'pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4,da;q=0.2,de;q=0.2,fr;q=0.2'
}
http = Net::HTTP.new(uri.host, uri.port)
res = http.get(uri.request_uri, headers)
p res.body
❯ ruby get.rb [15:00:44]
"\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03\x8A\x8E\x05\x00\x00\x00\xFF\xFF\x03\x00)\xBBL\r\x02\x00\x00\x00"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment