|
@@ -0,0 +1,636 @@
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using System.Net;
|
|
|
+using System.Text;
|
|
|
+using System.Web;
|
|
|
+
|
|
|
+using System;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
+using System.Web.SessionState;
|
|
|
+using System.Net.Security;
|
|
|
+using System.Security.Cryptography.X509Certificates;
|
|
|
+
|
|
|
+namespace LeaRun.Util
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static class WebHelper
|
|
|
+ {
|
|
|
+ #region Host(获取主机名)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string Host
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return HttpContext.Current.Request.Url.Host;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region ResolveUrl(解析相对Url)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string ResolveUrl(string relativeUrl)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(relativeUrl))
|
|
|
+ return string.Empty;
|
|
|
+ relativeUrl = relativeUrl.Replace("\\", "/");
|
|
|
+ if (relativeUrl.StartsWith("/"))
|
|
|
+ return relativeUrl;
|
|
|
+ if (relativeUrl.Contains("://"))
|
|
|
+ return relativeUrl;
|
|
|
+ return VirtualPathUtility.ToAbsolute(relativeUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region HtmlEncode(对html字符串进行编码)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string HtmlEncode(string html)
|
|
|
+ {
|
|
|
+ return HttpUtility.HtmlEncode(html);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string HtmlDecode(string html)
|
|
|
+ {
|
|
|
+ return HttpUtility.HtmlDecode(html);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region UrlEncode(对Url进行编码)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string UrlEncode(string url, bool isUpper = false)
|
|
|
+ {
|
|
|
+ return UrlEncode(url, Encoding.UTF8, isUpper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string UrlEncode(string url, Encoding encoding, bool isUpper = false)
|
|
|
+ {
|
|
|
+ var result = HttpUtility.UrlEncode(url, encoding);
|
|
|
+ if (!isUpper)
|
|
|
+ return result;
|
|
|
+ return GetUpperEncode(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static string GetUpperEncode(string encode)
|
|
|
+ {
|
|
|
+ var result = new StringBuilder();
|
|
|
+ int index = int.MinValue;
|
|
|
+ for (int i = 0; i < encode.Length; i++)
|
|
|
+ {
|
|
|
+ string character = encode[i].ToString();
|
|
|
+ if (character == "%")
|
|
|
+ index = i;
|
|
|
+ if (i - index == 1 || i - index == 2)
|
|
|
+ character = character.ToUpper();
|
|
|
+ result.Append(character);
|
|
|
+ }
|
|
|
+ return result.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region UrlDecode(对Url进行解码)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string UrlDecode(string url)
|
|
|
+ {
|
|
|
+ return HttpUtility.UrlDecode(url);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string UrlDecode(string url, Encoding encoding)
|
|
|
+ {
|
|
|
+ return HttpUtility.UrlDecode(url, encoding);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Session操作
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void WriteSession<T>(string key, T value)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ HttpContext.Current.Session[key] = value;
|
|
|
+ HttpContext.Current.Session.Timeout = 60;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void WriteSession(string key, string value)
|
|
|
+ {
|
|
|
+ WriteSession<string>(key, value);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string GetSession(string key)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ if (HttpContext.Current.Session[key] != null)
|
|
|
+ return HttpContext.Current.Session[key] as string;
|
|
|
+ else
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void RemoveSession(string key)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ HttpContext.Current.Session.Contents.Remove(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Cookie操作
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void WriteCookie(string strName, string strValue)
|
|
|
+ {
|
|
|
+ HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
|
|
|
+ if (cookie == null)
|
|
|
+ {
|
|
|
+ cookie = new HttpCookie(strName);
|
|
|
+ }
|
|
|
+ cookie.Value = strValue;
|
|
|
+ HttpContext.Current.Response.AppendCookie(cookie);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void WriteCookie(string strName, string strValue, int expires)
|
|
|
+ {
|
|
|
+ HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
|
|
|
+ if (cookie == null)
|
|
|
+ {
|
|
|
+ cookie = new HttpCookie(strName);
|
|
|
+ }
|
|
|
+ cookie.Value = strValue;
|
|
|
+ cookie.Expires = DateTime.Now.AddMinutes(expires);
|
|
|
+ HttpContext.Current.Response.AppendCookie(cookie);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string GetCookie(string strName)
|
|
|
+ {
|
|
|
+ if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
|
|
|
+ {
|
|
|
+ return HttpContext.Current.Request.Cookies[strName].Value.ToString();
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void RemoveCookie(string CookiesName)
|
|
|
+ {
|
|
|
+ HttpCookie objCookie = new HttpCookie(CookiesName.Trim());
|
|
|
+ objCookie.Expires = DateTime.Now.AddYears(-5);
|
|
|
+ HttpContext.Current.Response.Cookies.Add(objCookie);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region GetFileControls(获取客户端文件控件集合)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static List<HttpPostedFile> GetFileControls()
|
|
|
+ {
|
|
|
+ var result = new List<HttpPostedFile>();
|
|
|
+ var files = HttpContext.Current.Request.Files;
|
|
|
+ if (files.Count == 0)
|
|
|
+ return result;
|
|
|
+ for (int i = 0; i < files.Count; i++)
|
|
|
+ {
|
|
|
+ var file = files[i];
|
|
|
+ if (file.ContentLength == 0)
|
|
|
+ continue;
|
|
|
+ result.Add(files[i]);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region GetFileControl(获取第一个有效客户端文件控件)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static HttpPostedFile GetFileControl()
|
|
|
+ {
|
|
|
+ var files = GetFileControls();
|
|
|
+ if (files == null || files.Count == 0)
|
|
|
+ return null;
|
|
|
+ return files[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region HttpWebRequest(请求网络资源)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string HttpWebRequest(string url)
|
|
|
+ {
|
|
|
+ return HttpWebRequest(url, string.Empty, Encoding.GetEncoding("utf-8"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string HttpWebRequest(string url, string parameters)
|
|
|
+ {
|
|
|
+ return HttpWebRequest(url, parameters, Encoding.GetEncoding("utf-8"), "POST");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string HttpWebRequest(string url, string parameters, string contentType, string Authorization, string app_key)
|
|
|
+ {
|
|
|
+ return HttpWebRequest(url, parameters, Encoding.GetEncoding("utf-8"), "POST", contentType, Authorization, app_key);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string HttpWebRequest(string url, string parameters, string mehtod, string contentType, string Authorization, string app_key)
|
|
|
+ {
|
|
|
+ return HttpWebRequest(url, parameters, Encoding.GetEncoding("utf-8"), mehtod, contentType, Authorization, app_key);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string HttpWebRequest(string url, string parameters, Encoding encoding, string mehtod = "POST",
|
|
|
+ string contentType = "application/x-www-form-urlencoded", string Authorization = null, string app_key = null, CookieContainer cookie = null, int timeout = 120000)
|
|
|
+ {
|
|
|
+ HttpWebRequest request = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ request = WebRequest.Create(url) as HttpWebRequest;
|
|
|
+ }
|
|
|
+
|
|
|
+ request.Timeout = timeout;
|
|
|
+ if (!string.IsNullOrEmpty(Authorization))
|
|
|
+ {
|
|
|
+ request.Headers["Authorization"] = Authorization;
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(app_key))
|
|
|
+ {
|
|
|
+ request.Headers["app_key"] = app_key;
|
|
|
+ }
|
|
|
+ request.CookieContainer = cookie;
|
|
|
+ request.ContentType = contentType;
|
|
|
+ request.Method = mehtod;
|
|
|
+ if (mehtod == "POST")
|
|
|
+ {
|
|
|
+ byte[] postData = encoding.GetBytes(parameters);
|
|
|
+ request.Method = "POST";
|
|
|
+ request.ContentType = contentType;
|
|
|
+ request.ContentLength = postData.Length;
|
|
|
+ using (Stream stream = request.GetRequestStream())
|
|
|
+ {
|
|
|
+ stream.Write(postData, 0, postData.Length);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mehtod == "PUT")
|
|
|
+ {
|
|
|
+ using (StreamWriter requestStream = new StreamWriter(request.GetRequestStream()))
|
|
|
+ {
|
|
|
+ requestStream.Write(parameters);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var response = (HttpWebResponse)request.GetResponse();
|
|
|
+ string result;
|
|
|
+ using (Stream stream = response.GetResponseStream())
|
|
|
+ {
|
|
|
+ if (stream == null)
|
|
|
+ return string.Empty;
|
|
|
+ using (var reader = new StreamReader(stream, encoding))
|
|
|
+ {
|
|
|
+ result = reader.ReadToEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ throw ex;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ private static X509Certificate2 GetSentosaCertificate()
|
|
|
+ {
|
|
|
+ X509Store userCaStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ userCaStore.Open(OpenFlags.ReadOnly);
|
|
|
+ X509Certificate2Collection certificatesInStore = userCaStore.Certificates;
|
|
|
+ X509Certificate2Collection findResult = certificatesInStore.Find(X509FindType.FindBySubjectName, "server", true);
|
|
|
+ X509Certificate2 clientCertificate = null;
|
|
|
+ if (findResult.Count == 1)
|
|
|
+ {
|
|
|
+ clientCertificate = findResult[0];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new Exception("Unable to locate the correct client certificate.");
|
|
|
+ }
|
|
|
+ return clientCertificate;
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ userCaStore.Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 去除HTML标记
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string NoHtml(string Htmlstring)
|
|
|
+ {
|
|
|
+
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
|
|
|
+
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"…", "", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"—", "", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"“", "", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring.Replace("<", "");
|
|
|
+ Htmlstring = Regex.Replace(Htmlstring, @"”", "", RegexOptions.IgnoreCase);
|
|
|
+ Htmlstring.Replace(">", "");
|
|
|
+ Htmlstring.Replace("\r\n", "");
|
|
|
+ Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
|
|
|
+ return Htmlstring;
|
|
|
+
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 格式化文本(防止SQL注入)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string Formatstr(string html)
|
|
|
+ {
|
|
|
+ System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
|
|
+ System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
|
|
+ System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
|
|
+ System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
|
|
+ System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
|
|
+ System.Text.RegularExpressions.Regex regex10 = new System.Text.RegularExpressions.Regex(@"select", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
|
|
+ System.Text.RegularExpressions.Regex regex11 = new System.Text.RegularExpressions.Regex(@"update", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
|
|
+ System.Text.RegularExpressions.Regex regex12 = new System.Text.RegularExpressions.Regex(@"delete", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
|
|
+ html = regex1.Replace(html, "");
|
|
|
+ html = regex2.Replace(html, "");
|
|
|
+ html = regex3.Replace(html, " _disibledevent=");
|
|
|
+ html = regex4.Replace(html, "");
|
|
|
+ html = regex10.Replace(html, "s_elect");
|
|
|
+ html = regex11.Replace(html, "u_pudate");
|
|
|
+ html = regex12.Replace(html, "d_elete");
|
|
|
+ html = html.Replace("'", "’");
|
|
|
+ html = html.Replace(" ", " ");
|
|
|
+ return html;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #region 根据OneNet平台的鉴权修改Http请求
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static string HttpWebRequest_oneNet(string url, string parameters, Encoding encoding, string mehtod = "POST",
|
|
|
+ string contentType = "application/x-www-form-urlencoded", string Authorization = null, string api_key = null, CookieContainer cookie = null, int timeout = 120000)
|
|
|
+ {
|
|
|
+ mehtod = mehtod.ToUpper();
|
|
|
+ HttpWebRequest request = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ request = WebRequest.Create(url) as HttpWebRequest;
|
|
|
+ }
|
|
|
+
|
|
|
+ request.Timeout = timeout;
|
|
|
+ if (!string.IsNullOrEmpty(Authorization))
|
|
|
+ {
|
|
|
+ request.Headers["Authorization"] = Authorization;
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(api_key))
|
|
|
+ {
|
|
|
+ request.Headers["api-key"] = api_key;
|
|
|
+ }
|
|
|
+ request.CookieContainer = cookie;
|
|
|
+ request.ContentType = contentType;
|
|
|
+ request.Method = mehtod;
|
|
|
+ if (mehtod == "POST")
|
|
|
+ {
|
|
|
+ byte[] postData = encoding.GetBytes(parameters);
|
|
|
+ request.Method = "POST";
|
|
|
+ request.ContentType = contentType;
|
|
|
+ request.ContentLength = postData.Length;
|
|
|
+ using (Stream stream = request.GetRequestStream())
|
|
|
+ {
|
|
|
+ stream.Write(postData, 0, postData.Length);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (mehtod == "PUT")
|
|
|
+ {
|
|
|
+ using (StreamWriter requestStream = new StreamWriter(request.GetRequestStream()))
|
|
|
+ {
|
|
|
+ requestStream.Write(parameters);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var response = (HttpWebResponse)request.GetResponse();
|
|
|
+ string result;
|
|
|
+ using (Stream stream = response.GetResponseStream())
|
|
|
+ {
|
|
|
+ if (stream == null)
|
|
|
+ return string.Empty;
|
|
|
+ using (var reader = new StreamReader(stream, encoding))
|
|
|
+ {
|
|
|
+ result = reader.ReadToEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return "接口调用错误";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|