PYTHON实现操作中发送POST,GET请求

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

PYTHON实现操作中发送POST,GET请求

首先感谢温侯大大的范例:[PYTHON发送get,post请求](https://wenku.my7c.com/article/144123235905198592?channel_level=%E9%87%91%E8%9D%B6%E4%BA%91%E7%A4%BE%E5%8C%BA%7C%E6%90%9C%E7%B4%A2%7C%E7%BB%BC%E5%90%88&productLineId=1) 在此基础上,添加了dynamicobject转JSON方法: ```language import clr clr.AddReference("System") clr.AddReference("System.Web.Extensions") clr.AddReference("Kingdee.BOS.Core") clr.AddReference("Kingdee.BOS") clr.AddReference("Newtonsoft.Json") clr.AddReference("System.Data") clr.AddReference("Kingdee.BOS.DataEntity") clr.AddReference("Kingdee.BOS.App") clr.AddReference("Kingdee.BOS.App.Core") clr.AddReference("Kingdee.BOS.ServiceHelper") clr.AddReference("Kingdee.BOS.ServiceFacade.Common") import sys from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Core.DependencyRules import * from Kingdee.BOS.Core.Bill import * from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import * from System import * from System.Data import * from System.Net import * from System.Text import * from System.IO import * from Kingdee.BOS.App.Data import * from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Core.DynamicForm import * from Kingdee.BOS.Core.Metadata.EntityElement import * from Kingdee.BOS.Core.Metadata.FieldElement import * from Kingdee.BOS.Orm.DataEntity import * from Kingdee.BOS.ServiceFacade import * from System.Collections.Generic import * from System.Threading import * from System.Security.Cryptography import * from System.Web.Script.Serialization import * from System.Collections.Generic import Dictionary from Newtonsoft.Json.Linq import * sys.setdefaultencoding('utf-8') def OnPreparePropertys (e): e.FieldKeys.Add("BillNo") # e.FieldKeys.Add("Entity") def BeginOperationTransaction(e): opCode=this.FormOperation.Operation.ToUpperInvariant() if (opCode=="DELETE"): for billObj in e.DataEntitys: billno= billObj["BillNo"] postcontent=("fbillno:{0}").format(billno) url="http://192.168.12.218:8001//api/Values/PostInfo" postdata=dynamicobjecttojson(postcontent) result=post(url,postdata) pass def get(url): webRequest = WebRequest.Create(url) webRequest.Method = "GET"; webResponse = webRequest.GetResponse(); stream = webResponse.GetResponseStream(); streamReader =StreamReader(stream, Encoding.GetEncoding("utf-8")) result = streamReader.ReadToEnd(); return result def post(url,postdata): webRequest = HttpWebRequest.Create(url); webRequest.Method = "POST" webRequest.ContentType = "application/json" data=Encoding.ASCII.GetBytes(postdata); webRequest.ContentLength = data.Length; webRequest.GetRequestStream().Write(data, 0, data.Length) webRequest.GetRequestStream().Flush() webRequest.GetRequestStream().Close() webResponse =webRequest.GetResponse() streamReader =StreamReader( webResponse .GetResponseStream(),Encoding.GetEncoding("utf-8") ) result=streamReader.ReadToEnd() return result def dynamicobjecttojson(dyobject): jsonSerializerProxy = JsonSerializerProxy(Encoding.UTF8, False) jsonData = jsonSerializerProxy.Serialize(dyobject) return jsonData ```


我拿你这个改了按钮的,也好用的,感谢分享!

PYTHON实现操作中发送POST,GET请求

首先感谢温侯大大的范例:[PYTHON发送get,post请求](https://wenku.my7c.com/article/144123235905198592?channel_level=%E9%87%91%E8%9D%...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息