Python6 EchoServer HelloServer에서 entity body를 쓰는 부분이 self.wfile.write() 부분인 것을 설명했다. 브라우저에 localhost:8000/helloPath! 를 치면 화면에 helloPath! 를 보여주려면 어떻게 할까? self.wfile.write(self.path[1:].encode())로 바꾸면 된다. 브라우저에 localhost:8000/helloPath! 라고 치면 우리가 작성한 코드에서 self.path에는 "/helloPath!"가 된다. 요청 -> 서버(요청한 url에서 path는 self.path로 사용가능) -> 응답 더 궁금하면 BaseHTTPRequestHandler에 대한 정보를 찾아보면 좋을 것이다. 2020. 7. 1. HelloServer 브라우저에서 localhost:8000를 입력하면 Hello, HTTP!를 화면에 보여주는 예를 살펴보자. HelloServer.py 코드 from http.server import HTTPServer, BaseHTTPRequestHandler class HelloHandler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type', 'text/plain; charset=utf-8') self.end_headers() self.wfile.write("Hello, HTTP!\n".encode()) if __name__ == '__main__': server_address = ('', 8.. 2020. 7. 1. 이전 1 2 다음