Web.Config
1 |
<globalization responseEncoding="gb2312"/> |
CS文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.Text; using System.IO; using System.Xml; using System.Collections; using System.Diagnostics; namespace WebPortal { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { CoreProxy.Class1 c = new CoreProxy.Class1(); c.test1(); } protected void Button2_Click(object sender, EventArgs e) { webquerst1(); } public void webquers2() { string html = null; string url = "http://china.alibaba.com/keyword/promotion.htm?catId=14"; WebRequest req = WebRequest.Create(url); req.Method = "POST"; WebResponse res = req.GetResponse(); Stream receiveStream = res.GetResponseStream(); Encoding encode = Encoding.GetEncoding("gb2312"); StreamReader sr = new StreamReader(receiveStream, encode); char[] readbuffer = new char[256]; int n = sr.Read(readbuffer, 0, 256); while (n > 0) { string str = new string(readbuffer, 0, n); html += str; n = sr.Read(readbuffer, 0, 256); } System.Console.Write(html); } //成功!,利用WebRequest 一次Post提交XML内容 public void webquerst1() { WebRequest request = WebRequest.Create("http://192.168.1.244/WebPortal/PortalHandler.ashx"); // Set the Method property of the request to POST. request.Method = "POST"; // Create POST data and convert it to a byte array. System.Xml.XmlDocument xmlpostdata = new System.Xml.XmlDocument(); xmlpostdata.Load(Server.MapPath("XML/20097.xml")); string postData = HttpUtility.HtmlEncode(xmlpostdata.InnerXml); //普通字符串内容 //string postData = "你好,1232355 abdcde"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream(); // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. //Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. //Console.WriteLine(responseFromServer); // Clean up the streams. reader.Close(); dataStream.Close(); response.Close(); } protected void Button3_Click(object sender, EventArgs e) { WebClientPost(); } //重点!! 成功 利用Webclient Post 按字段的方式提交每个字段的内容给服务器端 public void WebClientPost() { System.Xml.XmlDocument xmlpostdata = new System.Xml.XmlDocument(); xmlpostdata.Load(Server.MapPath("XML/OrderClient.xml")); string OrderClient = HttpUtility.HtmlEncode(xmlpostdata.InnerXml); xmlpostdata.Load(Server.MapPath("XML/Order.xml")); string Order = HttpUtility.HtmlEncode(xmlpostdata.InnerXml); xmlpostdata.Load(Server.MapPath("XML/TargetOut.xml")); string TargetOut = HttpUtility.HtmlEncode(xmlpostdata.InnerXml); xmlpostdata.Load(Server.MapPath("XML/ArrayOfOrderDetail.xml")); string ArrayOfOrderDetail = HttpUtility.HtmlEncode(xmlpostdata.InnerXml); System.Net.WebClient WebClientObj = new System.Net.WebClient(); System.Collections.Specialized.NameValueCollection PostVars = new System.Collections.Specialized.NameValueCollection(); //添加值域 PostVars.Add("OrderClient", OrderClient); PostVars.Add("Order", Order); PostVars.Add("TargetOut", TargetOut); PostVars.Add("ArrayOfOrderDetail", ArrayOfOrderDetail); try { byte[] byRemoteInfo = WebClientObj.UploadValues("http://192.168.1.244/WebPortal/PlaceOrder.ashx", "POST", PostVars); //下面都没用啦,就上面一句话就可以了 string sRemoteInfo = System.Text.Encoding.Default.GetString(byRemoteInfo); //这是获取返回信息 Debug.WriteLine(sRemoteInfo); } catch { } } //未测试,使用WebClient 一次性提交POst public static string SendPostRequest(string url, string postString) { byte[] postData = Encoding.UTF8.GetBytes(postString); WebClient client = new WebClient(); client.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); client.Headers.Add("ContentLength", postData.Length.ToString()); byte[] responseData = client.UploadData(url, "POST", postData); return Encoding.Default.GetString(responseData); } /// <summary> /// 这个是用WEbRequest 提交到WEbService 的例子 /// </summary> /// <param name="URL"></param> /// <param name="MethodName"></param> /// <param name="Pars"></param> /// <returns></returns> public static XmlDocument QueryPostWebService(String URL, String MethodName, Hashtable Pars) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; SetWebRequest(request); byte[] data = EncodePars(Pars); WriteRequestData(request, data); return ReadXmlResponse(request.GetResponse()); } private static void SetWebRequest(HttpWebRequest request) { request.Credentials = CredentialCache.DefaultCredentials; request.Timeout = 10000; } private static void WriteRequestData(HttpWebRequest request, byte[] data) { request.ContentLength = data.Length; Stream writer = request.GetRequestStream(); writer.Write(data, 0, data.Length); writer.Close(); } private static byte[] EncodePars(Hashtable Pars) { return Encoding.UTF8.GetBytes(ParsToString(Pars)); } private static String ParsToString(Hashtable Pars) { StringBuilder sb = new StringBuilder(); foreach (string k in Pars.Keys) { if (sb.Length > 0) { sb.Append("&"); } sb.Append(HttpUtility.UrlEncode(k) + "=" + HttpUtility.UrlEncode(Pars[k].ToString())); } return sb.ToString(); } private static XmlDocument ReadXmlResponse(WebResponse response) { StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); String retXml = sr.ReadToEnd(); sr.Close(); XmlDocument doc = new XmlDocument(); doc.LoadXml(retXml); return doc; } private static void AddDelaration(XmlDocument doc) { XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", null); doc.InsertBefore(decl, doc.DocumentElement); } protected void Button4_Click(object sender, EventArgs e) { } } } |
ashx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Diagnostics; using System.IO; using System.Xml; namespace WebPortal { /// <summary> /// $codebehindclassname$ 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class PortalHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { string testGet = context.Request["testGet"]; string testPost = context.Request["testPost"]; Debug.WriteLine(testGet); Debug.WriteLine(testPost); //一次性提交的方式 //获得内容长度 int len = context.Request.ContentLength; //获得所有内容流 StreamReader reader = new StreamReader(context.Request.InputStream); //读取内容 string responseFromServer = reader.ReadToEnd(); //字段提交Post方式 string a1 = context.Request["A1"]; string a2 = context.Request["A2"]; string a3 = context.Request["A3"]; //解析Html编码 string re = HttpUtility.HtmlDecode(a1); XmlDocument xd = new XmlDocument(); //加载XML xd.LoadXml(re); context.Response.ContentType = "text/plain"; context.Response.Write(testGet); } public bool IsReusable { get { return false; } } } } |
转自:http://www.cnblogs.com/goody9807/archive/2011/10/08/2202265.html
View Detailsusing System; using System.IO; using System.Net; using System.Text; using System.Web; namespace HP.Common { /// <summary> /// 信息 /// </summary> public class InfoCollect { /// <summary> /// 获取内网页面内容 /// </summary> /// <param name="url"></param> /// <returns></returns> public static string GetPageByInner(string url) { return GetPage("http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + (HttpContext.Current.Request.ServerVariables["SERVER_PORT"] == "80" ? "" : ":" + HttpContext.Current.Request.ServerVariables["SERVER_PORT"]) + url); } /// <summary> /// 获取公网url内容(GET) /// </summary> /// <param name="url"></param> /// <returns></returns> public static string GetPage(string url) { return GetPage(url, "GET", null); } /// <summary> /// 获取公网url内容(Post方法) /// </summary> /// <param name="url"></param> […]
View Details我做了三年的+Perl程序员,以编程为生已经有7年。我生活中克路治-那波卡市(Cluj-Napoca),这是罗马尼亚第二大城市。 四年前我就开始困惑于一个问题:作为一个程序员,我的生活水平和其他国家的程序员有多大差距?那时候我的税后收入大概是每月700欧元(约5830 元,1欧元=8.331人民币)。就当时罗马尼亚的经济水平,整个社会的平均工资低于每月325.91欧元(2715元),我的收入差不多是全国水平的两 倍,这让我产生了一种打死都不离开这里的感觉。然而,这只是一种心理感觉,尽管和其他人比起来我挣得很多,但事实上每月我都挣扎在贫困线上。这种拮据归咎 于我缺乏收入管理,背后的原因是我的妻子刚刚成为一名律师,她现在的收入几乎为0, 克路治-那波卡市的程序员的收入情况 尽管市场在不断的浮动变化,那波卡市里一名有经验的程序员的基本收入大概是这个水平(这里说的收入都是税后水平——净收入): 最初是每月400欧元(3330元) 每6个月涨100欧元(833元)工资 根据个别情况,这个数目会有差异,可能更好,可能更坏。 从好的情况讲,一个程序员的工资水平可以用以下方式获得跳跃式的增长: 通过直接要求 通过跳槽 通过离开公司然后反聘回来 当然,还可以卓越的成绩来跟公司讨价还价,获得涨薪 从不好的情况讲,如果发生下列情况,一个程序员的工资会增长的很慢: 公司的运营状况不好 不善于谈判 一个不关心员工的老板。 自己表现不好 所以,当发现一个有5年经验的程序员拿月薪税后1500欧元(12.5K元)而一个7年经验的只拿月薪1700欧元(14k元)时,就不足为奇了。 几大城市收入/消费水平的比较 最近我发现了这个numbeo网站,它收集世界上各大城市的消费及收入信息,而且,它能让你将两个城市的物价水平,工资及购买力进行比较,你能根据它估算出在另一个城市生活所需要的收入水平。根据它提供的数据,我发现以我现在在那波卡市的收入水平不可能在世界其它城市里生活的很好。(表中的金额都以欧元为单位) 城市 参考收入 收入1 租房价格 收入2 年净收入 伦敦 4762 5,396.93 1,884.00 7,280.93 87,371.20 柏林 2784 3,155.20 800.00 3,955.20 47,462.40 阿姆斯特丹 3826 4,336.13 3,026.00 7,362.13 88,345.60 纽约 4848 5,494.40 2,214.00 7,708.40 92,500.80 旧金山 4484 5,081.87 2,216.00 7,297.87 87,574.40 这些数字的含义 参考收入 – 是指在那个城市如果想让生活质量达到我现在在那波卡市的生活水平,你需要达到的收入水平。按我在那波卡市每月1500欧元收入算。上表中显示的都是税后收入或净收入。 收入1 – 是指如果想在那个城市的生活质量达到在那波卡市的每月1700欧元生活水平质量,你需要达到的净收入。我列出1700欧元水平的原因是它很接近我的水平,这是有7年工作经验的程序员的平均水平。 租房价格 – 一个三居室的价格,非市中心。 收入2 – 这是收入1栏和租房价格的汇总 年净收入 – 是指收入2栏乘以12个月 需要更多的数据 如果在上表中再加入一列各城市的程序员的平均收入信息,那就更清晰了。遗憾的是,我搜查过的大多数网站上只提供税前年收入。因为各地的税收情况各 异,不可能计算出税后收入。所以,如果你是一个在上述城市生活的程序员,并且知道当地平均净收入的情况,请在评论里分享给大家,我会更新到文章里。 克路治-那波卡市(Cluj-Napoca)程序员的生活情况 因为罗马尼亚较低的购买力水平,人们日常的消费水平也比较低。看一下numbeo网站上关于那波卡市的价格水平信息。 1700欧元每月你可以过上任何想要的生活——如果你是个喜欢聚会的人。你的生活大概可以是这样: 一顿三餐(3餐12欧元 * 30 days = 360 欧元/月). 每个周末去最贵的俱乐部玩乐(一晚30欧元 * 8晚 = 240欧元/月) […]
View Details如果你是一个网页设计师,那么你应该清楚字体在网页设计中的重要性,本文再向你推荐 20 个新鲜免费的字体。 God Bless America Astrolyte Beautiful ES Chocolate Dealer 20DB My special angel font Braxton free font G-Unit Rough Brush Script Eletroz Lainie Day Koch Antiqua Zier ALEX BRUSH FontPunk.com font Porter Sans Block Bumple Rolling Rocker Headline Text Frank-n-Plank Science Fair via djdesignerlab 转自:http://www.oschina.net/news/45512/20-fresh-new-free-fonts-designers
View Details