Python uses commands to enable the http. server method, pythonhttp. server
Preface
If you urgently need a simple Web Server, but you do not want to download and install complex HTTP service programs, such as Apache and ISS. Then, Python may help you. Python can be used to complete a simple built-in HTTP server. Therefore, you can display your directories and files in HTTP mode. Compile only needs to do one thing, that is, install a Python.
If you are not familiar with installing python, refer to these two articles:
- Python3.5 in win10 Environment
- Install the latest Python 3.6 in Linux
After installation, you can start the text of this article.
Python uses commands to enable the http. server
If you want to use the command E: \ zpic as the download directory, then cd in cmd to this directory and execute the command:
python -m SimpleHTTPServer
The default port number is 8000. the root directory of the server is the working directory for running python commands.
If an error is prompted:
No module named SimpleHTTPServer
Try the following command:
python -m http.server
Use http: // 127.0.0.1: 8000 to access contents in the directory.
Or add the port number:python -m http.server 80
Use http: // 127.0.0.1 to access contents in the directory
Disable the server:
1) dos
Enter "ctrl + C" in the running interface to stop
2) python script
Port listening and related python processes need to be stopped
def stop_server(server)server.sorket.close()
======================================
The following three modules are used to build an http server:
1) BaseHTTPServer: provides basic Web services and processor classes, including HTTPServer and BaseHTTPRequestHandler;
2) SimpleHTTPServer: contains the SimpleHTTPRequestHandler class that executes GET and HEAD requests;
3) CGIHTTPServer: contains the CGIHTTPRequestHandler class for processing POST requests and execution.
Summary
The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.