0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【備忘録】Python3のシンプルHTTPサーバ(SimpleHTTPRequestHandler)を使って、POSTでもGETと同じ挙動をさせる

0
Posted at

概要

python -m http.serverでPOSTメソッドを送っても

<h1>Error response</h1>
<p>Error code: 501</p>
<p>Message: Unsupported method ('POST').</p>
<p>Error code explanation: 501 - Server does not support this operation.</p>

を返してきて使えなかったため、簡単にできる解決法を探した。

ソースコード

server.py
from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer

PORT = 8000


class RequestHandler(SimpleHTTPRequestHandler):
    def do_POST(self):
        super().do_GET()


with TCPServer(('', PORT), RequestHandler) as s:
    print(f'URL: http://127.0.0.1:{PORT}')
    s.serve_forever()

参考ページ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?