Created
July 2, 2019 15:19
-
-
Save angelikatyborska/bb463a7261a021cbfc4cda9410f63f49 to your computer and use it in GitHub Desktop.
HTTP(S) request via socket in Ruby
This file contains 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
# HTTP | |
sock = TCPSocket.new('example.com', 80); | |
sock.write("GET /path HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n"); | |
puts sock.read; | |
sock.close; | |
# HTTPS | |
sock = TCPSocket.new('example.com', 443) | |
sslsock = OpenSSL::SSL::SSLSocket.new(sock) | |
sslsock.connect | |
sslsock.write("GET /path HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n") | |
puts sslsock.read | |
sslsock.close | |
sock.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment