修复BUG:WebApiTools.Get方法支持https协议
修复BUG:WebApiTools.Get方法支持https协议
支持HTTPS协议的GET方法: C# Code: /// <summary> /// 客户端统一提交数据 /// </summary> /// <param name="url">WebAPI核心URL地址</param> /// <param name="param">URL参数</param> /// <returns>返回数据</returns> public static string Get(string url, string param, string contentType) { try { System.Net.HttpWebRequest request; if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase)) { ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; ServicePointManager.CheckCertificateRevocationList = false; ServicePointManager.DefaultConnectionLimit = 512; ServicePointManager.Expect100Continue = false; request = WebRequest.Create(url + (param == "" ? "" : "?") + param) as HttpWebRequest; request.ProtocolVersion = HttpVersion.Version10; request.KeepAlive = false; } else { request = (System.Net.HttpWebRequest)WebRequest.Create(url + (param == "" ? "" : "?") + param); } //request = (HttpWebRequest)WebRequest.Create(url + (param == "" ? "" : "?") + param); request.Method = "GET"; request.ContentType = contentType;//text/html;charset=UTF-8; #region 获取网页内容太大的话,就加下面这两句代码 request.Headers["Accept-Encoding"] = "gzip,deflate"; request.AutomaticDecompression = DecompressionMethods.GZip; #endregion request.Timeout = WebApiTools.TimeOut; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); return retString; } catch (WebException ex) { string result = "GET:操作失败!\r\n" + ex.Message; if (ex.Response != null) result = result + "\r\n" + GetResponseText(ex.Response); throw new Exception(result); } catch (Exception ex) { throw new Exception("GET:操作失败!\r\n" + ex.Message); } } //来源:C/S框架网(www.csframework.com) QQ:23404761 支持HTTPS协议的POST方法: C# Code: /// <summary> /// 客户端统一提交数据 /// </summary> /// <param name="url">WebAPI核心URL地址</param> /// <param name="data">提交的数据</param> /// <param name="contentType">指定request.ContentType</param> /// <returns>返回数据</returns> public static string Post(string url, string data, string contentType) { string returnData = null; try { string strURL = url; System.Net.HttpWebRequest request; if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase)) { ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; ServicePointManager.CheckCertificateRevocationList = false; ServicePointManager.DefaultConnectionLimit = 512; ServicePointManager.Expect100Continue = false; request = WebRequest.Create(url) as HttpWebRequest; request.ProtocolVersion = HttpVersion.Version10; request.KeepAlive = false; } else { request = (System.Net.HttpWebRequest)WebRequest.Create(strURL); } request.Method = "POST"; request.ContentType = contentType;// "application/json;charset=UTF-8";//POST必须使用JSON格式 string paraUrlCoded = data; byte[] payload; payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded); request.ContentLength = payload.Length; request.Timeout = WebApiTools.TimeOut; Stream writer = request.GetRequestStream(); writer.Write(payload, 0, payload.Length); writer.Close(); System.Net.HttpWebResponse response; response = (System.Net.HttpWebResponse)request.GetResponse(); System.IO.Stream s; s = response.GetResponseStream(); string StrDate = ""; string strValue = ""; StreamReader Reader = new StreamReader(s, Encoding.GetEncoding("utf-8")); while ((StrDate = Reader.ReadLine()) != null) { strValue += StrDate + "\r\n"; } returnData = strValue; return returnData.Trim() + "\n"; } catch (WebException ex) { string result = "POST:操作失败!\r\n" + ex.Message; if (ex.Response != null) result = result + "\r\n" + GetResponseText(ex.Response); throw new Exception(result); } catch (Exception ex) { throw new Exception("POST:操作失败!\r\n" + ex.Message); } } private static string GetResponseText(WebResponse response) { string text; using (StreamReader sr = new StreamReader(response.GetResponseStream())) { text = sr.ReadToEnd(); } if ((response is HttpWebResponse)) { int status = (int)(response as HttpWebResponse).StatusCode; if (status == 429) text = "流量访问限制!" + text; } return text; } //来源:C/S框架网(www.csframework.com) QQ:23404761
参考文档:
权限管理发现两处BUG及解决方法 企业版:CommonData.cs ,GetEmptyTable()方法有Bug SqlBuilder.cs文件,新增AddParam方法, 支持OutPut参数 开发框架修正重要bug,使用SqlDataAdapter.Update方法后没有关闭SQL连接 BUG: dalUser.CopyPermission方法 C#.NET扩展的动态对象支持动态属性和方法以及Json格式与对象互转 修复BUG:WebApiTools.Post方法支持Https协议 C#.NET IP端口绑定SSL证书支持HTTPS协议(用于Win服务自承载WebApi服务器) - C/S框架网原创 原创WebApi框架:采用HTTPS协议SelfHosting,Windows服务承载WebApi服务 微信小程序使用https协议的WebApi后端应用服务(Win服务宿主或自承载) 阿里云购买免费版个人SSL证书 - 微信小程序后端应用服务必须是HTTPS协议 C#正则表达式判断url是否网络路径(http/ftp/https三种协议) WCF开发框架 - BasicHttpBinding绑定的web.config与C#代码配置(支持https协议) IIS部署ssl证书支持https协议 阿里云虚拟主机部署ssl证书支持https协议
其它资料:
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 | |