title: using python urllib2 to send POST request and get response
body: <p>I am trying to get the HTML page back from sending a POST request:</p>
  
  <pre><code>import httplib 
  import urllib 
  import urllib2 
  from BeautifulSoup import BeautifulSoup
  
  
  headers = {
      'Host': 'digitalvita.pitt.edu',
      'Connection': 'keep-alive',
      'Content-Length': '325', 
      'Origin': 'https://digitalvita.pitt.edu',
      'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1',
      'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
      'Accept': 'text/javascript, text/html, application/xml, text/xml, */*',
      'Referer': 'https://digitalvita.pitt.edu/index.php',
      'Accept-Encoding': 'gzip,deflate,sdch',
      'Accept-Language': 'en-US,en;q=0.8',
      'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
      'Cookie': 'PHPSESSID=lvetilatpgs9okgrntk1nvn595'
  }
  
  data = {
      'action': 'search',
      'xdata': '&lt;search id="1"&gt;&lt;context type="all" /&gt;&lt;results&gt;&lt;ordering&gt;familyName&lt;/ordering&gt;&lt;pagesize&gt;100000&lt;/pagesize&gt;&lt;page&gt;1&lt;/page&gt;&lt;/results&gt;&lt;terms&gt;&lt;name&gt;d&lt;/name&gt;&lt;school&gt;All&lt;/school&gt;&lt;/terms&gt;&lt;/search&gt;',
      'request': 'search'
  }
  
  data = urllib.urlencode(data) 
  print data 
  req = urllib2.Request('https://digitalvita.pitt.edu/dispatcher.php', data, headers) 
  response = urllib2.urlopen(req)
  the_page = response.read()
  
  soup=BeautifulSoup(the_page)
  print soup
  </code></pre>
  
  <p>Can anyone tell me how to make it work?</p>