Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccc63eb
commit 0ffa064
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python3.7 | ||
from http.server import HTTPServer, BaseHTTPRequestHandler | ||
|
||
from io import BytesIO | ||
|
||
|
||
|
||
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): | ||
|
||
def do_GET(self): | ||
self.send_response(200) | ||
self.end_headers() | ||
self.wfile.write(b'Hello, world!') | ||
|
||
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(b'This is POST request. ') | ||
response.write(b'Received: ') | ||
response.write(body) | ||
print(self.headers) | ||
print(body) | ||
self.wfile.write(response.getvalue()) | ||
|
||
|
||
httpd = HTTPServer(('localhost', 8100), SimpleHTTPRequestHandler) | ||
httpd.serve_forever() |