Created
October 7, 2017 14:53
-
-
Save MichelleDalalJian/f89c989e825f092b0ca428c390a6edb1 to your computer and use it in GitHub Desktop.
Exploring the HyperText Transport Protocol You are to retrieve the following document using the HTTP protocol in a way that you can examine the HTTP Response headers. http://data.pr4e.org/intro-short.txt There are three ways that you might retrieve this web page and look at the response headers: Preferred: Modify the socket1.py program to retrie…
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
import socket | |
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
mysock.connect(('data.pr4e.org', 80)) | |
cmd = 'GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n'.encode() | |
mysock.send(cmd) | |
while True: | |
data = mysock.recv(512) | |
if (len(data) < 1): | |
break | |
print(data.decode()) | |
mysock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
solution