본문 바로가기
파이썬

파이썬 BaseHTTPRequestHandler.do_POST ()에서 HTTP 메시지 본문을 추출하는 방법은 무엇입니까?

by º기록 2020. 10. 3.
반응형

BaseHTTPRequestHandler do_POST () 메소드에서 self.headers 속성을 ​​통해 POST 요청의 헤더에 액세스 할 수 있습니다. 그러나 메시지 본문에 액세스하기위한 유사한 속성을 찾을 수 없습니다. 그런 다음 어떻게해야합니까?

 

해결 방법

 

다음과 같이 do_POST 메소드에서 POST 본문에 액세스 할 수 있습니다.

python 2

content_len = int(self.headers.getheader('content-length', 0))

python 3

content_len = int(self.headers.get('Content-Length'))

그런 다음 데이터를 읽습니다.

post_body = self.rfile.read(content_len)

 

참조 페이지 https://stackoverflow.com/questions/5975952

 

 

반응형

댓글