c#实现BPM系统网络传输接口,http协议,post

BPM通过http协议实现网络传输,语言使用.net(c#),在这里只提供一个接口,具体代码如下,请参照:

public string MakeRequest(string parameters)

{

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);//验证服务器证书回调自动验证

var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);

request.Method = Method.ToString();

request.ContentLength = 0;

request.ContentType = ContentType;

if (!string.IsNullOrEmpty(PostData) && Method == HttpVerb.POST)//如果传送的数据不为空,并且方法是post

{

var encoding = new UTF8Encoding();

var bytes = Encoding.GetEncoding("utf-8").GetBytes(PostData);//编码方式按需求进行更改,UTF-8

request.ContentLength = bytes.Length;

using (var writeStream = request.GetRequestStream())

{

writeStream.Write(bytes, 0, bytes.Length);

}

}

if (!string.IsNullOrEmpty(PostData) && Method == HttpVerb.PUT)//如果传送的数据不为空,并且方法是put

{

var encoding = new UTF8Encoding();

var bytes = Encoding.GetEncoding("utf-8").GetBytes(PostData);//编码方式按需求进行更改,UTF-8

request.ContentLength = bytes.Length;

using (var writeStream = request.GetRequestStream())

{

writeStream.Write(bytes, 0, bytes.Length);

}

}

using (var response = (HttpWebResponse)request.GetResponse())

{

var responseValue = string.Empty;

if (response.StatusCode != HttpStatusCode.OK)

{

var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);

throw new ApplicationException(message);

}

// grab the response

using (var responseStream = response.GetResponseStream())

{

if (responseStream != null)

using (var reader = new StreamReader(responseStream))

{

responseValue = reader.ReadToEnd();

}

}

return responseValue;

}

}

以上代码为基于个人BPM程序所提供的http协议实现接口,如果有具体需求可在评论区提出,大家可以起讨论。

相关推荐
唐青枫6 小时前
C#.NET 定时任务与队列利器:Hangfire 完整教程
c#·.net
hez201012 小时前
Runtime Async - 步入高性能异步时代
c#·.net·.net core·clr
mudtools1 天前
.NET驾驭Word之力:玩转文本与格式
c#·.net
唐青枫1 天前
C#.NET 数据库开发提速秘籍:SqlSugar 实战详解
c#·.net
mudtools2 天前
.NET驾驭Word之力:理解Word对象模型核心 (Application, Document, Range)
c#·.net
大飞pkz2 天前
【设计模式】C#反射实现抽象工厂模式
设计模式·c#·抽象工厂模式·c#反射·c#反射实现抽象工厂模式
唐青枫2 天前
从入门到进阶:C#.NET Stopwatch 计时与性能测量全攻略
c#·.net
未来之窗软件服务3 天前
幽冥大陆(二)RDIFSDK 接口文档:布草洗涤厂高效运营的技术桥梁C#—东方仙盟
开发语言·c#·rdif·仙盟创梦ide·东方仙盟
1uther3 天前
Unity核心概念⑨:Screen
开发语言·游戏·unity·c#·游戏引擎
阿幸软件杂货间3 天前
Office转PDF转换器v1.0.py
开发语言·pdf·c#