Python HTTP操作基本应用方式简述

开发 后端
Python HTTP操作在实际编程中是一个比较重要的操作技术。我们可以通过这里介绍的一些代码片段来充分掌握这一应用方式。

Python编程语言在实际应用中给开发人员带来了非常大的好处。我们可以先通过这篇文章中介绍的有关Python HTTP操作的相关内容对这一编程语言的应用方式有一个详细的了解,并增加对其的印象。

Python HTTP操作代码示例:

  1. import urllib2,cookielib  
  2. class HTTPRefererProcessor(urllib2.BaseHandler):  
  3. def __init__(self):  
  4. self.referer = None   
  5. def http_request(self, request):  
  6. if ((self.referer is not None) and  
  7. not request.has_header("Referer")):  
  8. request.add_unredirected_header("Referer", self.referer)  
  9. return request   
  10. def http_response(self, request, response):  
  11. self.referer = response.geturl()  
  12. return response   
  13. https_request = http_request 
  14. https_response = http_response   
  15. cj = cookielib.CookieJar()  
  16. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj),
     HTTPRefererProcessor(),)  
  17. urllib2.install_opener(opener)   
  18. data = 'msisdn=999999' 
  19. request = urllib2.Request(  
  20. url = 'http://203.117.16.171:8080/webgamecode/webcore?action=topup',  
  21. headers = {'Content-Type': 'application/x-www-form-urlencoded'},  
  22. datadata = data)  
  23. ret = opener.open(request)  
  24. content = ret.read()   
  25. print content  

以上就是我们对Python HTTP操作的相关介绍。

【编辑推荐】

  1. Python PAMIE模块实现IE自动化
  2. Python字符串显示实际应用技巧分享
  3. Python Socket编程实现网络编程
  4. Python base64模块基本概念总结
  5. Python取得文件列表基本应用方式浅谈
责任编辑:曹凯 来源: 博客园
相关推荐

2010-03-04 09:27:34

调用Python脚本

2010-03-03 14:40:37

Python打包方法

2010-03-03 10:03:55

Python连接Sql

2010-03-03 14:30:05

Python set类

2010-03-03 16:08:26

Python取得文件列

2010-03-03 15:17:46

Python调用MyS

2010-02-02 14:45:35

C++ typeof

2013-12-12 16:10:21

Lua脚本语言

2010-03-03 13:22:08

Python正则表达式

2010-01-25 13:45:04

Android单选框

2010-03-04 14:57:08

Python解密VBS

2010-02-02 17:33:17

C++友元函数

2010-07-08 15:24:17

SNMP trap

2010-03-05 15:47:59

Python Stri

2010-03-04 15:52:59

Python构造列表

2010-02-04 17:16:33

C++调用python

2010-03-03 13:32:08

Python压缩文件

2010-02-25 10:52:29

WCF响应服务

2010-02-26 13:40:28

WCF消息头

2010-02-25 18:04:02

WCF IIS宿主
点赞
收藏

51CTO技术栈公众号