|
@@ -212,159 +212,6 @@ namespace Azylee.YeahWeb.HttpUtils
|
|
|
return (int)Math.Ceiling((DateTime.Now - beginTime).TotalSeconds);//操作成功
|
|
return (int)Math.Ceiling((DateTime.Now - beginTime).TotalSeconds);//操作成功
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- [Obsolete]
|
|
|
|
|
- public static string PostJson(string url, string param)
|
|
|
|
|
- {
|
|
|
|
|
- string rs = null;
|
|
|
|
|
- ServicePointManager.DefaultConnectionLimit = 300;
|
|
|
|
|
- CookieContainer cookieContainer = new CookieContainer();
|
|
|
|
|
- // 设置提交的相关参数
|
|
|
|
|
- HttpWebRequest request = null;
|
|
|
|
|
- HttpWebResponse SendSMSResponse = null;
|
|
|
|
|
- Stream dataStream = null;
|
|
|
|
|
- StreamReader SendSMSResponseStream = null;
|
|
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- request = WebRequest.Create(url) as HttpWebRequest;
|
|
|
|
|
- request.Method = "POST";
|
|
|
|
|
- request.KeepAlive = false;
|
|
|
|
|
- request.ServicePoint.ConnectionLimit = 300;
|
|
|
|
|
- request.AllowAutoRedirect = true;
|
|
|
|
|
- request.Timeout = 10000;
|
|
|
|
|
- request.ReadWriteTimeout = 10000;
|
|
|
|
|
- request.ContentType = "application/json";
|
|
|
|
|
- request.Accept = "application/xml";
|
|
|
|
|
- request.Headers.Add("X-Auth-Token", HttpUtility.UrlEncode("OpenStack"));
|
|
|
|
|
- string strContent = param;
|
|
|
|
|
- byte[] bytes = Encoding.UTF8.GetBytes(strContent);
|
|
|
|
|
- request.Proxy = null;
|
|
|
|
|
- request.CookieContainer = cookieContainer;
|
|
|
|
|
- using (dataStream = request.GetRequestStream())
|
|
|
|
|
- {
|
|
|
|
|
- dataStream.Write(bytes, 0, bytes.Length);
|
|
|
|
|
- }
|
|
|
|
|
- SendSMSResponse = (HttpWebResponse)request.GetResponse();
|
|
|
|
|
- if (SendSMSResponse.StatusCode == HttpStatusCode.RequestTimeout)
|
|
|
|
|
- {
|
|
|
|
|
- if (SendSMSResponse != null)
|
|
|
|
|
- {
|
|
|
|
|
- SendSMSResponse.Close();
|
|
|
|
|
- SendSMSResponse = null;
|
|
|
|
|
- }
|
|
|
|
|
- if (request != null)
|
|
|
|
|
- {
|
|
|
|
|
- request.Abort();
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- SendSMSResponseStream = new StreamReader(SendSMSResponse.GetResponseStream(), Encoding.GetEncoding("utf-8"));
|
|
|
|
|
- string strRespone = SendSMSResponseStream.ReadToEnd();
|
|
|
|
|
-
|
|
|
|
|
- return strRespone;
|
|
|
|
|
- }
|
|
|
|
|
- catch (Exception ex)
|
|
|
|
|
- {
|
|
|
|
|
-
|
|
|
|
|
- if (dataStream != null)
|
|
|
|
|
- {
|
|
|
|
|
- dataStream.Close();
|
|
|
|
|
- dataStream.Dispose();
|
|
|
|
|
- dataStream = null;
|
|
|
|
|
- }
|
|
|
|
|
- if (SendSMSResponseStream != null)
|
|
|
|
|
- {
|
|
|
|
|
- SendSMSResponseStream.Close();
|
|
|
|
|
- SendSMSResponseStream.Dispose();
|
|
|
|
|
- SendSMSResponseStream = null;
|
|
|
|
|
- }
|
|
|
|
|
- if (SendSMSResponse != null)
|
|
|
|
|
- {
|
|
|
|
|
- SendSMSResponse.Close();
|
|
|
|
|
- SendSMSResponse = null;
|
|
|
|
|
- }
|
|
|
|
|
- if (request != null)
|
|
|
|
|
- {
|
|
|
|
|
- request.Abort();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- finally
|
|
|
|
|
- {
|
|
|
|
|
- if (dataStream != null)
|
|
|
|
|
- {
|
|
|
|
|
- dataStream.Close();
|
|
|
|
|
- dataStream.Dispose();
|
|
|
|
|
- dataStream = null;
|
|
|
|
|
- }
|
|
|
|
|
- if (SendSMSResponseStream != null)
|
|
|
|
|
- {
|
|
|
|
|
- SendSMSResponseStream.Close();
|
|
|
|
|
- SendSMSResponseStream.Dispose();
|
|
|
|
|
- SendSMSResponseStream = null;
|
|
|
|
|
- }
|
|
|
|
|
- if (SendSMSResponse != null)
|
|
|
|
|
- {
|
|
|
|
|
- SendSMSResponse.Close();
|
|
|
|
|
- SendSMSResponse = null;
|
|
|
|
|
- }
|
|
|
|
|
- if (request != null)
|
|
|
|
|
- {
|
|
|
|
|
- request.Abort();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return rs;
|
|
|
|
|
- }
|
|
|
|
|
- [Obsolete]
|
|
|
|
|
- public static T PostJson<T>(string url, string param, string encoding = "utf-8")
|
|
|
|
|
- {
|
|
|
|
|
- ServicePointManager.DefaultConnectionLimit = 300;
|
|
|
|
|
- CookieContainer cookieContainer = new CookieContainer();
|
|
|
|
|
- // 设置提交的相关参数
|
|
|
|
|
- HttpWebRequest request = null;
|
|
|
|
|
- HttpWebResponse SendSMSResponse = null;
|
|
|
|
|
- Stream dataStream = null;
|
|
|
|
|
- StreamReader SendSMSResponseStream = null;
|
|
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- Encoding myEncoding = Encoding.GetEncoding(encoding);
|
|
|
|
|
- request = WebRequest.Create(url) as HttpWebRequest;
|
|
|
|
|
- request.Method = "POST";
|
|
|
|
|
- request.KeepAlive = false;
|
|
|
|
|
- request.ServicePoint.ConnectionLimit = 300;
|
|
|
|
|
- request.AllowAutoRedirect = true;
|
|
|
|
|
- request.Timeout = 10000;
|
|
|
|
|
- request.ReadWriteTimeout = 10000;
|
|
|
|
|
- request.ContentType = "application/json";
|
|
|
|
|
- request.Accept = "application/xml";
|
|
|
|
|
- request.Headers.Add("X-Auth-Token", HttpUtility.UrlEncode("OpenStack"));
|
|
|
|
|
- string strContent = param;
|
|
|
|
|
- byte[] bytes = myEncoding.GetBytes(strContent);
|
|
|
|
|
- request.Proxy = null;
|
|
|
|
|
- request.CookieContainer = cookieContainer;
|
|
|
|
|
- using (dataStream = request.GetRequestStream())
|
|
|
|
|
- {
|
|
|
|
|
- dataStream.Write(bytes, 0, bytes.Length);
|
|
|
|
|
- }
|
|
|
|
|
- SendSMSResponse = (HttpWebResponse)request.GetResponse();
|
|
|
|
|
- if (SendSMSResponse.StatusCode != HttpStatusCode.RequestTimeout)
|
|
|
|
|
- {
|
|
|
|
|
- SendSMSResponseStream = new StreamReader(SendSMSResponse.GetResponseStream(), Encoding.GetEncoding("utf-8"));
|
|
|
|
|
- string response = SendSMSResponseStream.ReadToEnd();
|
|
|
|
|
- T result = JsonConvert.DeserializeObject<T>(response);
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- catch (Exception e) { }
|
|
|
|
|
- finally
|
|
|
|
|
- {
|
|
|
|
|
- if (dataStream != null) dataStream.Close();
|
|
|
|
|
- if (SendSMSResponseStream != null) SendSMSResponseStream.Close();
|
|
|
|
|
- if (SendSMSResponse != null) SendSMSResponse.Close();
|
|
|
|
|
- if (request != null) request.Abort();
|
|
|
|
|
- }
|
|
|
|
|
- return default(T);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// http下载文件
|
|
/// http下载文件
|
|
|
/// </summary>
|
|
/// </summary>
|