Category : http

I am trying to read the HTTP response sent by my sample python server. But for some reason my client is unable to read the response body, it can only see the headers. response = {"foo"} class MyServer(BaseHTTPRequestHandler): def do_POST(self): self.send_response(200) self.send_header("Content-Type", "application/json; charset=utf-8") self.send_header("Content-Length", len(response)) self.send_header("Connection", "close") # self.send_header(bytes(response, encoding=’utf8′)) self.end_headers() self.wfile.write(response.encode()) What I ..

Read more

I am running a python3 http server on my localhost – server.py from http.server import CGIHTTPRequestHandler, HTTPServer import os def main(): os.chdir(".") handler = CGIHTTPRequestHandler handler.cgi_directories = ["/cgi-bin"] port = 8080 try: server = HTTPServer(("", port), handler) print("Server running on port {}…".format(port)) server.serve_forever() except KeyboardInterrupt: print("nServer stopped!") server.socket.close() if __name__ == ‘__main__’: main() And here ..

Read more