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協議實現接口,如果有具體需求可在評論區提出,大家可以起討論。