Testing http.server GET/POST Service with Python 3
If you want to test the API service you wrote locally, you can write an easy http service. The example is as follows.
from http.server import HTTPServer, BaseHTTPRequestHandler
from io import BytesIO
class HTTPRequestService(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b'ONly POST')
def do_POST(self):
content_length = int(self.headers['Content-Length'])
body = self.rfile.read(content_length)
self.send_response(200)
self.end_headers()
response = BytesIO()
response.write(body)
self.wfile.write(response.getvalue())
httpd = HTTPServer(('localhost', 8000), HTTPRequestService)
httpd.serve_forever()
Can't find the information you're looking for?
You have examined the knowledge base in detail, but if you cannot find the information you need,
Create a Support Ticket-
How to Open Ports in Windows?
5155 2
-
How to Grant Windows Administrator Privileges?
2775 0
-
How to install Webmin on Ubuntu?
3265 2
-
Linux SSH Terminal Commands and Explanations
3013 3
-
CentOS Stream 10 Update Commands
3227 1
-
CentOS Stream 9 Update Commands
5571 2
-
CentOS Stream 8 Update Commands
3325 0
-
What is FreeBSD?
2935 2
-
Out: 452 4.3.1 Insufficient system storage
3114 2
-
Turning Off Automatic Updates in Windows Operating Systems
3904 1