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%...
点击下载文档
本文2024-09-16 18:19:52发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-21448.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章