Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Run a Simple HTTP Server on Windows Using Python

Running a simple HTTP server can be incredibly useful for various tasks such as testing web applications, serving static files, or sharing files over a local network. While there are many ways to do this, one of the simplest and most effective methods is to use Python's built-in http.server module. This article will guide you through the steps to set up and run an HTTP server on a Windows machine using Python.

Python is a versatile programming language that comes pre-installed with a module called http.server, which allows you to quickly set up an HTTP server with minimal effort. This is particularly useful for developers and system administrators who need a quick and temporary server for testing purposes.

Examples:

  1. Installing Python: If you don't have Python installed on your Windows machine, you can download it from the official Python website (https://www.python.org/). Follow the installation instructions provided on the site.

  2. Opening Command Prompt: Open the Command Prompt by pressing Win + R, typing cmd, and hitting Enter.

  3. Navigating to Your Directory: Use the cd command to navigate to the directory where you want to serve files. For example, if you want to serve files from C:\Users\YourUsername\Documents, you would type:

    cd C:\Users\YourUsername\Documents
  4. Running the HTTP Server: Once you're in the desired directory, you can start the HTTP server by typing the following command:

    python -m http.server 8000

    This command will start an HTTP server on port 8000. You can change the port number if needed.

  5. Accessing the Server: Open a web browser and go to http://localhost:8000. You should see a list of files and directories in the directory you specified.

  6. Stopping the Server: To stop the server, go back to the Command Prompt window where the server is running and press Ctrl + C.

Note: If you encounter an error stating that the python command is not recognized, it may be because Python is not added to your system's PATH. You can add Python to your PATH by following these steps:

  • Right-click on 'This PC' or 'Computer' on your desktop or in File Explorer.
  • Select 'Properties'.
  • Click on 'Advanced system settings'.
  • Click on the 'Environment Variables' button.
  • In the 'System variables' section, find the Path variable and click 'Edit'.
  • Add the path to your Python installation (e.g., C:\Python39\) and click 'OK'.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.