dhl: URL的编码问题。

ok

注:“你好”的编码:
Encoding.Default编码:%c4%e3%ba%c3
Encoding.UTF8编码:%e4%bd%a0%e5%a5%bd
Encoding.GetEncoding("gb2312"):%c4%e3%ba%c3
public ActionResult Sms(string sms)
        {
            if(!string.IsNullOrEmpty(sms))
            {
                string url = "http://9.1x.x8.xx:8080/xx/sms/push_mt.jsp?cpid=xx&cppwd=123&phone=13241856009";
                url += "&msgcont=" + HttpUtility.UrlEncode("你好测试", Encoding.Default);
                Utility.HttpHelper.Get(url, Encoding.Default);
                ViewData["info"] = "ok";
            }
            return View();
        }
/// <summary>
        /// 模拟Get提交数据
        /// </summary>
        /// <param name="url">Get地址</param>
        /// <param name="encode">编码,注:</param>
        /// <returns></returns>
		public static string Get(string url, Encoding encode)
		{
			var request = (HttpWebRequest)WebRequest.Create(url);
			request.Method = "GET";
			request.ContentType = "text/html;charset=UTF-8";

			var response = (HttpWebResponse)request.GetResponse();
			var myResponseStream = response.GetResponseStream();
			var myStreamReader = new StreamReader(myResponseStream, encode);
			string retString = myStreamReader.ReadToEnd();
			myStreamReader.Close();
			myResponseStream.Close();
			return retString;
		}
posted @ 2010-06-02 16:23  肚肚  阅读(247)  评论(0编辑  收藏  举报