WebService Python http.server

0

I am developing a small webservice, when I enter localhots: 8000 it shows me this is a test, but rarely the post method is not working for me, because when I want to send variables to it in the url or in a form, these are not reflected or the Chrome tools mark me that the action was canceled when submit, my python code is as follows:

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'This is a test')

    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)
        self.wfile.write(response.getvalue())


httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)
httpd.serve_forever()

My html is this:

<form action="localhost:8000" method="post">
  First name:<br>
  <input type="text" name="firstname" <br>
  Last name:<br>
  <input type="text" name="lastname" <br><br>
  <input type="submit" >
</form>

Thank you very much for being able to help me

    
asked by Pony94 12.06.2018 в 00:18
source

0 answers