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

相关推荐
阿蒙Amon1 小时前
C#扩展方法全解析:给现有类型插上翅膀的魔法
开发语言·c#
江山如画,佳人北望15 小时前
C#程序入门
开发语言·windows·c#
与火星的孩子对话16 小时前
Unity进阶课程【六】Android、ios、Pad 终端设备打包局域网IP调试、USB调试、性能检测、控制台打印日志等、C#
android·unity·ios·c#·ip
future141216 小时前
C#每日学习日记
java·学习·c#
军训猫猫头19 小时前
1.如何对多个控件进行高效的绑定 C#例子 WPF例子
开发语言·算法·c#·.net
葬歌倾城1 天前
JSON的缩进格式方式和紧凑格式方式
c#·json
Eiceblue2 天前
使用 C# 发送电子邮件(支持普通文本、HTML 和附件)
开发语言·c#·html·visual studio
小小小小王王王2 天前
hello判断
开发语言·c#
金增辉2 天前
基于C#的OPCServer应用开发,引用WtOPCSvr.dll
c#
future14122 天前
C#学习日记
开发语言·学习·c#