Skip to content

Instantly share code, notes, and snippets.

@aaronmoodie
Created July 5, 2010 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronmoodie/464042 to your computer and use it in GitHub Desktop.
Save aaronmoodie/464042 to your computer and use it in GitHub Desktop.
def download_file(url)
request = "GET #{url} HTTP/1.0\r\n\r\n"
host = /^https?:\/\/([^\/]+)/.match(url.to_s)
socket = TCPSocket.open(host[1].to_s,80)
socket.print(request)
# find beginning of response body
buffer = ""
while !buffer.match("\r\n\r\n") do
buffer += socket.read(1)
end
return socket.read(3000)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment