Posted By

bcmoney on 12/10/10


Tagged

python proxy


Versions (?)

proxy.py


 / Published in: Python
 

URL: http://bcmoney-mobiletv.com/blog/2009/05/01/the-server-side-proxy/

Source of inspiration for tiny code: http://coreygoldberg.blogspot.com/2008/09/python-vs-java-http-get-request.html

Python – Passing URL Parameters Variable To Python: http://erunways.com/python-passing-url-parameters-variable-to-python/

  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3.  
  4. import cgitb
  5. import cgi
  6. import urllib
  7.  
  8. cgitb.enable()
  9.  
  10. params = cgi.FieldStorage()
  11. u = params.getvalue('url')
  12. f = params.getvalue('f')
  13. e = params.getvalue('e')
  14.  
  15. if u is None:
  16. print "** ERROR **"
  17. elif len(u) == 0:
  18. url = "http://example.com"
  19. else:
  20. url = u
  21.  
  22. if f is None:
  23. print "** ERROR **"
  24. elif len(f) == 0:
  25. format = "text/plain"
  26. else:
  27. format = f
  28.  
  29. if e is None:
  30. print "** ERROR **"
  31. elif len(e) == 0:
  32. encoding = "utf-8"
  33. else:
  34. encoding = e
  35.  
  36. print "Content-Type: "+format";charset="+encoding
  37. print urllib.urlopen(url).read()

Report this snippet  

You need to login to post a comment.