I was trying to build a basic socket connection and to test it with curl . The code is given below:
import socket
HOST,PORT='',8888
listen_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST,PORT))
listen_socket.listen(1)
print(f"Serving HTTP on port {PORT} ...")
while True:
client_connection,client_address=listen_socket.accept()
request_data=client_connection.recv(1024)
print(request_data.decode('utf-8'))
http_response = b"""\
HTTP/1.1 200 OK
Hello , World !!!!!!!!!
"""
client_connection.sendall(http_response)
client_connection.close()
When I try to curl into curl localhost:8888
insted of receiving the message "Hello World !!!!" I get this curl: (1) Received HTTP/0.9 when not allowed
.