title: Sending and parsing an HTTP POST request with Python
body: <p>Could someone tell me what is going wrong with this simple server setup? It's based on the same code as in <a href="https://stackoverflow.com/questions/12946684/java-post-to-python-http-server-not-working">this question</a> and possibly a similar issue - but I need a POST request rather than a GET which was the eventual resolution in the other question? The problem is that <code>self.args</code> is empty when I had expected <code>{'verify': 'true'}</code>.</p>
  
  <p>Here's my POST request:</p>
  
  <pre><code>import requests
  
  url = 'http://localhost:8080/'
  data = {'verify': 'true'}
  response = requests.post(url, params=data)
  
  print response.text
  </code></pre>
  
  <p>And the handler which is running on localhost:</p>
  
  <pre><code>class MyHandler(BaseHTTPRequestHandler):
      def do_POST(self):
          self.query_string = self.rfile.read(int(self.headers['Content-Length']))
          self.args = dict(cgi.parse_qsl(self.query_string))
          self.send_response(200)
          self.end_headers()
          self.wfile.write("Content-type: text/html&lt;BR&gt;&lt;BR&gt;");
          self.wfile.write("&lt;HTML&gt;POST OK.&lt;BR&gt;&lt;BR&gt;");
  
  def main():
      server = HTTPServer(('', 8080), MyHandler)
      server.serve_forever()
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>The handler is outputting <code>Jamie-PC - - [15/Jul/2013 12:40:34] "POST /?verify=true HTTP/1.1" 200 -</code> in case that helps.</p>