So here’s the simple code:
import socket host = '192.168.1.152' port = 8080 client = socket.socket(socket.AF_INET,socket.SOCK_STREAM) client.connect((host,port)) client.send(b'GET / HTTP/1.1\r\nHost: 192.168.1.152\r\n\r\n') response = client.recv(4096) print(response)
So first create an object client
, the attributes are IPV4 (socket.AF_INET) and tcp (socket.SOCK_STREAM).
Use the send method to send http request, must send the msg in bytes, hence the b
.