바코94 2020. 7. 1. 16:34

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에 대한 정보를 찾아보면 좋을 것이다.