title: Failed to get the HTTP POST request body using Twisted
body: <p>I was trying to get the HTTP POST request body by using t.p.basic.LineReceiver but failed. My code is listed below:</p>
  
  <pre><code>from twisted.internet import reactor, protocol
  from twisted.protocols import basic
  
  class PrintPostBody(basic.LineReceiver):
      def __init__(self):
          self.line_no = 0
  
      def lineReceived(self, line):
          print '{0}: {1}'.format(str(self.line_no).rjust(3), repr(line))
          self.line_no += 1
  
      def connectionLost(self, reason):
          print "conn lost"
  
  class PPBFactory(protocol.ServerFactory):
      protocol = PrintPostBody
  
  def main():
      f = PPBFactory()
      reactor.listenTCP(80, f)
      reactor.run()
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>But when I was doing HTTP POST request to that machine at port 80, only the HTTP request headers were printed out.
  Sample output:</p>
  
  <pre><code>  0: 'POST / HTTP/1.0'
    1: 'Host: ###.##.##.##'
    2: 'Referer: http://#.#####.###/?ssid=0&amp;from=0&amp;bd_page_type=1&amp;uid=wiaui_1292470548_2644&amp;pu=sz%40176_229,sz%40176_208'
    3: 'Content-Length: 116'
    4: 'Origin: http://#.#####.###'
    5: 'Content-Type: application/x-www-form-urlencoded'
    6: 'Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'
    7: 'User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US) AppleWebKit/534.11 (KHTML, like Gecko) Chrome/9.0.565.0 Safari/534.11'
    8: 'Accept-Encoding: gzip,deflate,sdch'
    9: 'Accept-Language: en-US,en;q=0.8'
   10: 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3'
   11: 'Via: 1.1 #####.###.###.##:8080 (squid/2.6.STABLE21)'
   12: 'X-Forwarded-For: ###.##.###.###'
   13: 'Cache-Control: max-age=0'
   14: 'Connection: keep-alive'
   15: ''
  </code></pre>
  
  <p>So the connection was not closed here but the POST body was not received either.</p>
  
  <p>I have tested the network condition by running <code>sudo nc -l 80</code> and it did print out the HTTP POST request body.</p>
  
  <p>So, how could I get the HTTP POST request body using Twisted?
  Thank you very much.</p>