首页 > 编程 > Python > 正文

python 发送json数据操作实例分析

2019-11-02 14:08:27
字体:
来源:转载
供稿:网友

本文实例讲述了python 发送json数据操作。分享给大家供大家参考,具体如下:

# !/usr/bin/env python# -*- coding: utf-8 -*-import urllib2import urllibimport cookielibimport jsonimport httplibimport reimport requestsfrom lxml import etreeimport StringIOimport times = requests.session()print s.headerslogin_url = 'http://10.4.161.26:7001/itms/Logon.jsp'data = {'UserID':'015208','Password':'88888888','ScreenWidth':'1600'}# data = urllib.urlencode(data)headers = {  'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0'}response = s.post(login_url, data=data, headers=headers,timeout=10)print responseprint '--------------------'print response.status_codeprint '--------------------'# time.sleep(100)print response.contentprint response.headerstime.sleep(1)myurl='http://10.4.161.26:7001/itms/go?ComponentURL=/Main.view?TWIN=_top","_top'print s.get(myurl).contentmyurl='http://10.4.161.26:7001/itms/ReportWorkRecord/DailyInputWorkHourDialog.serv'data={"sysHead":{},"appHead":{},"body":{"WORKTYPE":"020","TASKNO":"zhaoyangjian","WORKCONTENT":"zhaoyangjian","WORKHOUR":"10","SERIALNO":"2018112100000106","USERID":"015208","REPORTDATE":"2018/11/21","ACCSTATE":"010","INPUTUSERID":"015208","INPUTDATE":"2018/11/21","INPUTORGID":"992200402","UPDATEUSERID":"015208","UPDATEDATE":"2018/11/21","UPDATEORGID":"992200402","ISINUSE":"1","SYS_SAVETMP":"","UPDATED_FIELD":"WORKTYPE,TASKNO,WORKCONTENT,WORKHOUR","novalid":'false'}}headers = {  'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0','Content-Type': 'application/json'}print '---------------------------------------------------------'print s.post(myurl, data=json.dumps(data), headers=headers).content

PS:这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线JSON代码检验、检验、美化、格式化工具:
http://tools.jb51.net/code/json

JSON在线格式化工具:
http://tools.jb51.net/code/jsonformat

在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson

json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.jb51.net/code/jsoncodeformat

在线json压缩/转义工具:
http://tools.jb51.net/code/json_yasuo_trans

更多Python相关内容感兴趣的读者可查看本站专题:《Python操作json技巧总结》、《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表