The main function of WebServer is to run the code, handle http requests and other services, such as common Apache, IIS, Nginx, etc. can be used to parse the code and process the request. The above kinds of containers (middleware) are powerful, but the installation configuration is troublesome. For a rookie like me, it may take a few days to set up a web server. If we’re building a web server that’s not designed to handle large-scale requests, but just for testing, then a quick and easy WebServer is critical.
- BaseHTTPServer: Provides basic web services and handler classes, namely HTTPServer and BaseHTTPRequestHandler.
- SimpleHTTPServer: Contains the SimpleHTTPRequestHandler class that performs GET and HEAD requests.
- CGIHTTPServer: Contains classes for handling POST requests and executing CGIHTTPRequestHandler
Python built a lot of useful libraries, open the browser at this time, access localhost: 8000 port.
Since it’s very convenient to build a simple WebServer with python, I wrote a simple launcher, similar to SimpleHTTPServer. In order to facilitate the startup of the windows machine without the python environment, use the pyinstaller tool to package the py program into an exe executable.
After running, you can access it on other machines and download files!
The function can be imagined to play freely, for example:
- You can run programs on the server, parse a well-constructed py code, and execute system commands remotely. (If you are not on the same network segment, you need to forward the port)
- You can run the program on the server, instead of FTP and other tools, download the files on the server (when the server is linux, it is convenient to use)
PyWebServer [download address] (https://github.com/tengzhangchao/PyWebServer)