Created
June 30, 2010 07:59
-
-
Save reinh/458375 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'socket' | |
| require 'uri' | |
| class HttpClient | |
| include Socket::Constants | |
| def initialize(uri) | |
| @parsedURI = parseURI(uri) | |
| @socket = Socket.new(AF_INET, SOCK_STREAM, 0) | |
| socketAddress = Socket.pack_sockaddr_in(80,@parsedURI[2]) | |
| @socket.connect(socketAddress) | |
| end | |
| def parseURI(uri) | |
| return URI.split(uri) | |
| end | |
| def getStream | |
| @socket.print("GET #{@parsedURI[5]} HTTP/1.1\r\n\r\n") | |
| output = @socket.read | |
| puts output | |
| end | |
| end | |
| if __FILE__ == $0 | |
| testClient = HttpClient.new(ARGV[0]) | |
| testClient.getStream | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment