Socket programing

Viewed 25

Hello I'm doing a work on creating a connection between a client and a server, the point of the work is sending a GET request using only the sockets, we are using XAMPP as the servers, we have two txt files on htdocs and I want to request one or the other, but I'm having 404 not found. How do I fix this?

from socket import*

#IP, Porto do servidor 
HOST = '127.0.0.1'
PORT = 80

#Criar o socket TCP
clientSocket = socket(AF_INET, SOCK_STREAM)

#Estabelecer ligação ao servidor 
clientSocket.connect((HOST,PORT))

#Escolha entre Fernando Pessoa ou Luis de Camões
print('Qual o seu Poeta Favorito: ')
voto = input('1-Luis de Camoes ou 2-Fernando Pessoa' )

#Pedido de Get
pedidoHTTP = None
if(voto == '1'):
    pedidoHTTP =  f"GET /localhost/trabalho/1.txt HTTP/1.1\r\nHost: {HOST}:{PORT}\r\n\r\n".encode()
elif(voto == '2'):
    pedidoHTTP = f"GET /localhost/trabalho/2.txt HTTP/1.1\r\nHost: {HOST}:{PORT}\r\n\r\n".encode()
else:
    print('Pressione 1 ou 2 para ser valido')
    clientSocket.close()
       
clientSocket.sendall(pedidoHTTP)

#Ler a resposta do servidor
Rececao = clientSocket.recv(8000).decode()
0 Answers
Related