首页 / C# / C# - Lee 公共类库
C# - Lee 公共类库
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C# - Lee 公共类库,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含7700字,纯文字阅读大概需要12分钟。
内容图文
我的公共类库
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Text; using System.IO; using System.Net; using System.Web; using System.Web.UI; using CY.CommonLibrary.AspNet; using CY.CommonLibrary.Common; namespace Lee { public class Common { public static string Test_Swich = System.Configuration.ConfigurationManager.AppSettings["Test_Swich"]; //只要不为空,都为测试模式///<summary>/// 是否处于测试模式.只要不为空,都为测试模式 ///</summary>///<returns>布尔值</returns>publicstaticbool Is_测试模式() { if (Test_Swich != "") { returntrue; } returnfalse; } ///<summary>/// send_发送POST请求 ///</summary>///<param name="vServerPage"></param>///<param name="vPostData"></param>///<returns></returns>publicstaticstring send_发送POST请求(string vServerPage, string vPostData) #region { byte[] dataArray = Encoding.UTF8.GetBytes(vPostData); //创建请求 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(vServerPage); request.Method = "POST"; request.ContentLength = dataArray.Length; request.ContentType = "application/x-www-form-urlencoded"; request.Timeout = 5000; //创建输入流 Stream dataStream = null; try { dataStream = request.GetRequestStream(); } catch (Exception) { returnnull;//连接服务器失败 } //发送请求 dataStream.Write(dataArray, 0, dataArray.Length); dataStream.Close(); //读取返回消息string res = string.Empty; try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); res = reader.ReadToEnd(); reader.Close(); } catch (Exception ex) { returnnull;//连接服务器失败 } return res; } #endregion///<summary>/// send_发送Get请求 ///</summary>///<param name="url"></param>///<returns></returns>publicstaticstring send_发送GET请求(string url) #region { string str = ""; HttpWebRequest hwr = WebRequest.Create(url) as HttpWebRequest; hwr.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; hwr.Method = "GET"; hwr.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:34.0) Gecko/20100101 Firefox/34.0"; hwr.ContentType = "application/x-www-form-urlencoded"; hwr.Headers["Accept-Language"] = "zh-cn"; hwr.Timeout = 3000; try { HttpWebResponse _rep = hwr.GetResponse() as HttpWebResponse; Stream _stream = _rep.GetResponseStream(); StreamReader read = new StreamReader(_stream, Encoding.UTF8); str = read.ReadToEnd(); _rep.Close(); } catch (Exception ex) { log.WriteLog("数据获取超时? :" + ex.Message + "请求地址为:" + url); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Write("<style type=\"text/css\">#face{margin:0px auto;background: #9ee675;/* for Webkit */background: -webkit-gradient(linear, left top, left bottom, from(#9ee675), to(#78cb4c));/* for Firefox */background: -moz-linear-gradient(top, #9ee675, #78cb4c);/* for IE */filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=‘#9ee675‘,endColorstr=‘#78cb4c‘); color:#fff;border:1px solid #fff;border-radius:200px;text-indent:31px;width:97px;height:97px;font-size:66px;} *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: \"微软雅黑\"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 3.8em;text-align: center; font-size: 36px }</style><div style=\"padding: 24px 48px;\"> <h1 id=\"face\">:(</h1><p>数据超时..</p></div>"); HttpContext.Current.Response.End(); } return str; } #endregion///<summary>/// 发送一张笑脸 ///</summary>publicstaticvoid send_smiling_face(string str) #region { HttpContext.Current.Response.Write("<style type=\"text/css\">#face{margin:0px auto;background: #9ee675;/* for Webkit */background: -webkit-gradient(linear, left top, left bottom, from(#9ee675), to(#78cb4c));/* for Firefox */background: -moz-linear-gradient(top, #9ee675, #78cb4c);/* for IE */filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=‘#9ee675‘,endColorstr=‘#78cb4c‘); color:#fff;border:1px solid #fff;border-radius:200px;text-indent:31px;width:97px;height:97px;font-size:66px;} *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: \"微软雅黑\"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 3.8em;text-align: center; font-size: 36px }</style><div style=\"padding: 24px 48px;\"> <h1 id=\"face\">:)</h1><p>" + str + "</p></div>"); } #endregion///<summary>/// 发送一张哭脸 ///</summary>///<param name="str"></param>publicstaticvoid send_unhappy_face(string str) #region { HttpContext.Current.Response.Write("<style type=\"text/css\">#face{margin:0px auto;background: #9ee675;/* for Webkit */background: -webkit-gradient(linear, left top, left bottom, from(#9ee675), to(#78cb4c));/* for Firefox */background: -moz-linear-gradient(top, #9ee675, #78cb4c);/* for IE */filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=‘#9ee675‘,endColorstr=‘#78cb4c‘); color:#fff;border:1px solid #fff;border-radius:200px;text-indent:31px;width:97px;height:97px;font-size:66px;} *{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: \"微软雅黑\"; color: #333;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 3.8em;text-align: center; font-size: 36px }</style><div style=\"padding: 24px 48px;\"> <h1 id=\"face\">:(</h1><p>" + str + "</p></div>"); } #endregion///<summary>/// 去除html标签 ///</summary>///<param name="HTMLStr"></param>///<returns></returns>publicstring ParseTags(string HTMLStr) #region { return System.Text.RegularExpressions.Regex.Replace(HTMLStr, "<[^>]*>", ""); } #endregion///<summary>/// 网页弹出框 ///</summary>///<param name="obj"></param>publicstaticvoid alert(object obj) { HttpContext.Current.Response.Write("<script language=javascript>alert(‘" + obj.ToString() + "‘)</script>"); } ///<summary>/// 网页弹出框 ///</summary>///<param name="obj"></param>publicstaticvoid alert_back(object obj) { HttpContext.Current.Response.Write("<script language=javascript>alert(‘" + obj.ToString() + "‘);history.back();</script>"); } ///<summary>/// 网页弹出框 ///</summary>///<param name="obj"></param>publicstaticvoid alert_href(object obj,string url) { HttpContext.Current.Response.Write("<script language=javascript>alert(‘" + obj.ToString() + "‘);window.location.href=‘" + url + "‘;</script>"); } ///<summary>/// 在控制台打印出数据 ///</summary>///<param name="obj"></param>publicstaticvoid log_Console(object obj) { HttpContext.Current.Response.Write("<script>console.log(\"" + obj + "\")</script>"); } ///<summary>/// 打印 ///</summary>///<param name="obj"></param>publicstaticvoid print(object obj) { HttpContext.Current.Response.Write(obj.ToString()); } ///<summary>/// 输出,不换行,使用完直接结束 ///</summary>///<param name="obj"></param>publicstaticvoid echo(object obj) { HttpContext.Current.Response.Write(obj.ToString()); } ///<summary>/// 打印,带换行 ///</summary>///<param name="obj"></param>publicstaticvoid println(object obj) { HttpContext.Current.Response.Write(obj.ToString() + "<br />"); } ///<summary>/// 结束网页输出 ///</summary>publicstaticvoid End() { HttpContext.Current.Response.End(); } ///<summary>/// 清除网页输出 ///</summary>publicstaticvoid Clear() { HttpContext.Current.Response.Clear(); } } }
原文:http://www.cnblogs.com/CyLee/p/5324658.html
内容总结
以上是互联网集市为您收集整理的C# - Lee 公共类库全部内容,希望文章能够帮你解决C# - Lee 公共类库所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。