Skip to content

Instantly share code, notes, and snippets.

@Nehadsys
Created May 28, 2024 16:16
Show Gist options
  • Save Nehadsys/bc412d5428a4943cb95aa94ae26eb7e8 to your computer and use it in GitHub Desktop.
Save Nehadsys/bc412d5428a4943cb95aa94ae26eb7e8 to your computer and use it in GitHub Desktop.
Python simple socket get content requests for webservers
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ## Initializes a request
mysock.connect(('data.pr4e.org',80)) # connects to the request
cmd = 'GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n'.encode() # Gets the metadata from the HTTP host and encodes it too.
mysock.send(cmd) # Finally sends it
while True:
data = mysock.recv(512) # recives 512 characters only
if (len(data) < 1): # if less than 1 just break it.
break
print(data.decode()) # decodes the data
mysock.close() # closes it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment