前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python HTTP POST方法一例

Python HTTP POST方法一例

作者头像
py3study
发布2020-01-08 16:35:47
4180
发布2020-01-08 16:35:47
举报
文章被收录于专栏:python3

#!/usr/bin/env python

'''

Created on 2013-4-16

@author: zdh

create project: multimech-newproject my_project

run test: multimech-run my_project

'''

import httplib

import urllib

import time

import json

class Transaction(object):

def __init__(self):

self.custom_timers = {}

def run(self):

conn = httplib.HTTPConnection("localhost:8080")

headers = {"Content-type": "application/json"} #application/x-www-form-urlencoded,"Aceept":"text/plain"

params = ({"bindHyCardInfo":{"mobileNo":"1881026xxxx","userId":"2","hYCardno":line,"bankCardNo":"622xxxxxxxxxxxxx","ip":"127.0.0.1"},"header":{"version":"1.0.1","from":"1000","to":"2000","tid":line,"time":"12312","token":"SEW342WEER2342","ext":""}})

start = time.time()

conn.request("POST", "/core-oper/rest/bindHyCard", json.JSONEncoder().encode(params), headers)

response = conn.getresponse()

response_time = time.time()

data = response.read()

print data

conn.close()

transfer_time = time.time()

self.custom_timers['response received'] = response_time - start

self.custom_timers['content transferred'] = transfer_time - start

if __name__ == '__main__':

file = open("E://card.txt")

while 1:

lines = file.readlines()

if not lines:

break

for line in lines:

line = line.strip('\n')

trans = Transaction()

trans.run()

for timer in ('response received', 'content transferred'):

print '%s: %.5f secs' % (timer, trans.custom_timers[timer])

file.close()

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档