[Python] How to get link of client's request on a socket web server?

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to create a basic local web server using python sockets. You input a url into your browser (i.e. http://localhost/mysite.html), and it gives you back the requested file.

    s = socket(AF_INET, SOCK_STREAM)
    s.bind(('localhost', 8080))
    s.listen(1)

    while True:
    try:
    c, addr = s.accept()
    # Get the url and attempt to open the file
    except KeyBoardInterrupt:
    break
    s.close()


    I can obviously receive data using c (client socket), but I don't need that, I want the link that it's requesting from the server. I have read some of socket's documentation, and cannot find anything relevant to my question.

    Continue reading...

Compartilhe esta Página