python中发送get或post请求
2014-11-28 15:54
656 查看
示例
get
post[转]
get
import httplib import uuid import time url = "/KM/test.php?time=" url += str(int(time.time())) url += "&token=" url += uuid.uuid4().hex print url conn = httplib.HTTPConnection("a.bbbb.net:8008") headerdata = {"Host":"a.bbbb.net:8008", "Connection":"Keep-Alive", "Accept-Encoding":"gzip" } conn.request(method="GET",url=url,body=None,headers = headerdata) response = conn.getresponse() res= response.read() print res
post[转]
import httplib, urllib httpClient = None try: params = urllib.urlencode({'name': 'tom', 'age': 22}) headers = {"Content-type": "application/x-www-form-urlencoded" , "Accept": "text/plain"} httpClient = httplib.HTTPConnection("localhost", 80, timeout=30) httpClient.request("POST", "/test.php", params, headers) response = httpClient.getresponse() print response.status print response.reason print response.read() print response.getheaders() #获取头信息 except Exception, e: print e finally: if httpClient: httpClient.close()
相关文章推荐
- python用httplib模块发送get和post请求
- python发送GET或POST请求以便干一些趣事
- Python 使用requests模块发送GET和POST请求的实现代码
- python发送GET或POST请求以便干一些趣事
- python用httplib模块发送get和post请求
- python学习笔记:使用requests库发送get与post请求
- python 发送 get post请求
- python发送GET或POST请求以便干一些趣事
- 【转】python发送GET或POST请求以便干一些趣事
- python用httplib模块发送get和post请求
- python用httplib模块发送get和post请求
- python用httplib模块发送get和post请求
- python发送post和get请求
- python发送post和get请求
- python发送get/post/put/delete请求
- django 文件上传和菜单分级,mysql支持事务,F模块自增字段, python发送get,post请求
- Python 使用requests模块发送GET和POST请求的实现代码
- python用httplib模块发送get和post请求
- 大概看了一天python request源码。写下python requests库发送 get,post请求大概过程。
- python发送GET或POST请求以便干一些趣事