Chinaunix首页 | 论坛 | 博客
  • 博客访问: 456590
  • 博文数量: 56
  • 博客积分: 517
  • 博客等级: 下士
  • 技术积分: 751
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-12 18:16
文章分类

全部博文(56)

文章存档

2015年(2)

2014年(6)

2013年(29)

2012年(17)

2011年(2)

分类: Python/Ruby

2012-11-22 12:35:03

python写的http客户端测试程序,不到10行代码,简洁高效,直接上源码。
#httpclient.py

import http.client
with open("srv.file") as f:
data = f.read()
conn = http.client.HTTPConnection("192.168.59.128:8099")
#注意encode函数,否则报错
conn.request("POST", "sys.service.release.func", data.encode('utf-8'))
response = conn.getresponse()
data = response.read()
print(response.status, response.reason)
print('res:', data.decode('utf-8'))
conn.close()
阅读(4470) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~