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协议实现接口,如果有具体需求可在评论区提出,大家可以起讨论。

相关推荐
我是唐青枫13 小时前
C#.NET 索引器完全解析:语法、场景与最佳实践
c#·.net
FuckPatience17 小时前
C# 使用内存映射文件实现进程间通信
c#
kylezhao201919 小时前
如何在 C# 项目中使用 NLog 进行日志记录
开发语言·c#
小菱形_21 小时前
【C#】IEnumerable
开发语言·c#
爱敲点代码的小哥21 小时前
Directoy文件夹操作对象 、StreamReader和StreamWriter 和BufferedStream
开发语言·c#
CodeCraft Studio1 天前
Excel处理控件Aspose.Cells教程:使用C#在Excel中创建折线图
java·c#·excel·aspose.cells·excel图表·excel api库·excel折线图
m5655bj1 天前
C# 在 PDF 文档中添加电子签名
开发语言·pdf·c#
superman超哥1 天前
仓颉Actor模型的实现机制深度解析
开发语言·后端·python·c#·仓颉
一只蚊子01 天前
C# WinForms配置Halcon
windows·c#·halcon
阿蒙Amon1 天前
C#每日面试题-进程和线程的区别
java·面试·c#