본문 바로가기
웹(web)/백엔드-python

EchoServer

by 바코94 2020. 7. 1.

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

'웹(web) > 백엔드-python' 카테고리의 다른 글

JSON  (0) 2020.07.02
do_GET+ do_POST 예제2  (0) 2020.07.01
do_GET+ do_POST 예제1  (0) 2020.07.01
parse_qs(POST data parsing)  (0) 2020.07.01
HelloServer  (0) 2020.07.01