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#接口实现详解:从理论到实践,掌握面向对象编程的核心技巧
java·前端·c#
神所夸赞的夏天7 小时前
c#获取Datatable中某列最大或最小的行数据方法
开发语言·c#
我是唐青枫7 小时前
C#.NET serilog 详解
开发语言·c#·.net
future14128 小时前
项目开发日记
前端·学习·c#·游戏开发
我是苏苏17 小时前
C#基础:Winform桌面开发中窗体之间的数据传递
开发语言·c#
水果里面有苹果1 天前
20-C#构造函数--虚方法
java·前端·c#
[纳川]1 天前
把word中表格转成excle文件
开发语言·c#·word
lph19721 天前
快速分页wpf
c#
试行1 天前
C#System.Runtime.InteropServices.ExternalException (0x80004005): GDI+ 中发生一般性错误。
c#