http 协议集合,超级简单
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace App.Extend
{/// <summary>
/// ReqUtils
/// </summary>
public class ReqUtils
{
/// <summary>
/// 返回HttpContext.Current.Request对象
/// </summary>
public static HttpRequest Request
{
get { return HttpContext.Current.Request; }
}
/// <summary>
/// 从Form获取字符串类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string FormString(string name)
{
return Request.Form[name];
}
/// <summary>
/// 从Form获取字符串类型的参数,如果没有则返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static string FormString(string name, string defaultValue)
{
string value = Request.Form[name];
return value == null ? defaultValue : value;
}
/// <summary>
/// 从Query获取字符串类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string QueryString(string name)
{
return Request.QueryString[name];
}
/// <summary>
/// 从Query获取字符串类型的参数,如果没有则返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static string QueryString(string name, string defaultValue)
{
string value = Request.QueryString[name];
return value == null ? defaultValue : value;
}
/// <summary>
/// 先从Query获取参数,如果没有再从Form获取
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string GetString(string name)
{
/*
string value = Request.QueryString[name];
if (value == null)
{
value = Request.Form[name];
}
return value;*/
return Param(name);
}
public static string Param(string name)
{
return Request.Params[name];
}
public static string[] GetValues(string name)
{
string[] values = Request.Params.GetValues(name);
return values == null ? new string[0] : values;
}
/// <summary>
/// 先从Form获取参数,如果没有再从Query获取,如果仍然为空,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static string GetString(string name, string defaultValue)
{
string value = GetString(name);
return value == null ? defaultValue : value;
}
/// <summary>
/// 从Form获取参数的字符串数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string[] FormStringArray(string name)
{
string[] values = Request.Form.GetValues(name);
return values == null ? new string[0] : values;
}
/// <summary>
/// 从Query获取参数的字符串数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string[] QueryStringArray(string name)
{
string[] values = Request.QueryString.GetValues(name);
return values == null ? new string[0] : values;
}
/// <summary>
/// 从Form和Query获取参数的字符串数组,返回两个地方的总和
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string[] GetStringArray(string name)
{
string[] formArray = FormStringArray(name);
string[] queryArray = QueryStringArray(name);
string[] strArray = new string[formArray.Length + queryArray.Length];
Array.ConstrainedCopy(formArray, 0, strArray, 0, formArray.Length);
Array.ConstrainedCopy(queryArray, 0, strArray, formArray.Length, queryArray.Length);
return strArray;
}
/*================Boolean类型参数获取================*/
/// <summary>
/// 从Form获取bool类型的参数 支持"True" "true" "False" "false"
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool FormBool(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
if ("True" != str && "true" != str && "1" != str && "False" != str && "false" != str && "0" != str) throw new Exception("错误的Boolean表达式!");
return "True" == str || "true" == str || "1" == str;
}
/// <summary>
/// 从Form获取bool类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool FormBool(string name, bool defaultValue)
{
try
{
return FormBool(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取bool类型的参数 支持"True" "true" "False" "false"
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool? FormNullableBool(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) return null;
if ("True" != str && "true" != str && "1" != str && "False" != str && "false" != str && "0" != str) throw new Exception("错误的Boolean表达式!");
return "True" == str || "true" == str || "1" == str;
}
/// <summary>
/// 从Form获取bool类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool? FormNullableBool(string name, bool? defaultValue)
{
try
{
return FormNullableBool(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取int类型的参数 支持"True" "true" "False" "false"
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool QueryBool(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
if ("True" != str && "true" != str && "1" != str && "False" != str && "false" != str && "0" != str) throw new Exception("错误的Boolean表达式!");
return "True" == str || "true" == str || "1" == str;
}
/// <summary>
/// 从Query获取bool类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool QueryBool(string name, bool defaultValue)
{
try
{
return QueryBool(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取int类型的参数 支持"True" "true" "False" "false"
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool? QueryNullableBool(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) return null;
if ("True" != str && "true" != str && "1" != str && "False" != str && "false" != str && "0" != str) throw new Exception("错误的Boolean表达式!");
return "True" == str || "true" == str || "1" == str;
}
/// <summary>
/// 从Query获取bool类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool? QueryNullableBool(string name, bool? defaultValue)
{
try
{
return QueryNullableBool(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取bool参数的数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool[] FormBoolArray(string name)
{
string[] strArray = FormStringArray(name);
return Array.ConvertAll<string, bool>(strArray, delegate(string str)
{
if ("True" != str && "true" != str && "1" != str && "False" != str && "false" != str && "0" != str) throw new Exception("错误的Boolean表达式!");
return "True" == str || "true" == str || "1" == str;
});
}
/// <summary>
/// 从Query获取bool参数的数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool[] QueryBoolArray(string name)
{
string[] strArray = QueryStringArray(name);
return Array.ConvertAll<string, bool>(strArray, delegate(string str)
{
if ("True" != str && "true" != str && "1" != str && "False" != str && "false" != str && "0" != str) throw new Exception("错误的Boolean表达式!");
return "True" == str || "true" == str || "1" == str;
});
}
/// <summary>
/// 从Form和Query获取bool类型的参数 支持"True" "true" "False" "false"
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool GetBool(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
if ("True" != str && "true" != str && "1" != str && "False" != str && "false" != str && "0" != str) throw new Exception("错误的Boolean表达式!");
return "True" == str || "true" == str || "1" == str;
}
/// <summary>
/// 从Form和Query获取bool类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool GetBool(string name, bool defaultValue)
{
try
{
return GetBool(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form和Query获取bool类型的参数 支持"True" "true" "False" "false"
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool? GetNullableBool(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) return null;
if ("True" != str && "true" != str && "1" != str && "False" != str && "false" != str && "0" != str) throw new Exception("错误的Boolean表达式!");
return "True" == str || "true" == str || "1" == str;
}
/// <summary>
/// 从Form和Query获取bool类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static bool? GetNullableBool(string name, bool? defaultValue)
{
try
{
return GetNullableBool(name);
}
catch
{
return defaultValue;
}
}
/*================Int类型参数获取================*/
/// <summary>
/// 从Form获取int类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int FormInt(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return Convert.ToInt32(str);
}
/// <summary>
/// 从Form获取int类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static int FormInt(string name, int defaultValue)
{
try
{
return FormInt(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取int类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int? FormNullableInt(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) return null;
return Convert.ToInt32(str);
}
/// <summary>
/// 从Form获取int类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static int? FormNullableInt(string name, int? defaultValue)
{
try
{
return FormNullableInt(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取int类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int QueryInt(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return Convert.ToInt32(str);
}
/// <summary>
/// 从Query获取int类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static int QueryInt(string name, int defaultValue)
{
try
{
return QueryInt(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取int类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int? QueryNullableInt(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) return null;
return Convert.ToInt32(str);
}
/// <summary>
/// 从Query获取int类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static int? QueryNullableInt(string name, int? defaultValue)
{
try
{
return QueryNullableInt(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取int参数的数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int[] FormIntArray(string name)
{
string[] strArray = FormStringArray(name);
return Array.ConvertAll<string, int>(strArray, delegate(string str)
{
return Convert.ToInt32(str);
});
}
/// <summary>
/// 从Query获取int参数的数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int[] QueryIntArray(string name)
{
string[] strArray = QueryStringArray(name);
return Array.ConvertAll<string, int>(strArray, delegate(string str)
{
return Convert.ToInt32(str);
});
}
/// <summary>
/// 从query和form获取int数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int[] GetIntArray(string name)
{
string[] strArray = GetValues(name);
if(strArray==null)return new int[0];
return Array.ConvertAll<string, int>(strArray, delegate(string str)
{
return Convert.ToInt32(str);
});
}
/// <summary>
/// 从Form和Query获取int类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int GetInt(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return Convert.ToInt32(str);
}
/// <summary>
/// 从Form和Query获取int类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static int GetInt(string name, int defaultValue)
{
try
{
return GetInt(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form和Query获取int类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static int? GetNullableInt(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) return null;
return Convert.ToInt32(str);
}
/// <summary>
/// 从Form和Query获取int类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static int? GetNullableInt(string name, int? defaultValue)
{
try
{
return GetNullableInt(name);
}
catch
{
return defaultValue;
}
}
/*================Long类型参数获取================*/
/// <summary>
/// 从Form获取long 类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static long FormLong(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return Convert.ToInt64(str);
}
/// <summary>
/// 从Form获取long 类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static long FormLong(string name, long defaultValue)
{
try
{
return FormLong(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取long 类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static long? FormNullableLong(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) return null;
return Convert.ToInt64(str);
}
/// <summary>
/// 从Form获取long 类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static long? FormNullableLong(string name, long? defaultValue)
{
try
{
return FormNullableLong(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取long 类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static long QueryLong(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return Convert.ToInt64(str);
}
/// <summary>
/// 从Query获取long 类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static long QueryLong(string name, long defaultValue)
{
try
{
return QueryLong(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取long 类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static long? QueryNullableLong(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) return null;
return Convert.ToInt64(str);
}
/// <summary>
/// 从Query获取long 类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static long? QueryNullableLong(string name, long? defaultValue)
{
try
{
return QueryNullableLong(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取long类型参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static long[] FormLongArray(string name)
{
string[] strArray = FormStringArray(name);
return Array.ConvertAll<string, long>(strArray, delegate(string str)
{
return Convert.ToInt64(str);
});
}
/// <summary>
/// 从Query获取long类型参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static long[] QueryLongArray(string name)
{
string[] strArray = QueryStringArray(name);
return Array.ConvertAll<string, long>(strArray, delegate(string str)
{
return Convert.ToInt64(str);
});
}
/// <summary>
/// 从query和form获取long数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static long[] GetLongArray(string name)
{
string[] strArray = GetValues(name);
return Array.ConvertAll<string, long>(strArray, delegate(string str)
{
return Convert.ToInt64(str);
});
}
/// <summary>
/// 从Form和Query获取long 类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static long GetLong(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return Convert.ToInt64(str);
}
/// <summary>
/// 从Form和Query获取long 类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static long GetLong(string name, long defaultValue)
{
try
{
return GetLong(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form和Query获取long 类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static long? GetNullableLong(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) return null;
return Convert.ToInt64(str);
}
/// <summary>
/// 从Form和Query获取long 类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static long? GetNullableLong(string name, long? defaultValue)
{
try
{
return GetNullableLong(name);
}
catch
{
return defaultValue;
}
}
/*================Float类型参数获取================*/
/// <summary>
/// 从Form获取float类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static float FormFloat(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return float.Parse(str);
}
/// <summary>
/// 从Form获取float类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static float FormFloat(string name, float defaultValue)
{
try
{
return FormFloat(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取float类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static float? FormNullableFloat(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) return null;
return float.Parse(str);
}
/// <summary>
/// 从Form获取float类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static float? FormNullableFloat(string name, float? defaultValue)
{
try
{
return FormNullableFloat(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取float类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static float QueryFloat(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return float.Parse(str);
}
/// <summary>
/// 从Query获取float类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static float QueryFloat(string name, float defaultValue)
{
try
{
return QueryFloat(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取float类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static float? QueryNullableFloat(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) return null;
return float.Parse(str);
}
/// <summary>
/// 从Query获取float类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static float? QueryNullableFloat(string name, float? defaultValue)
{
try
{
return QueryNullableFloat(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取float参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static float[] FormFloatArray(string name)
{
string[] strArray = FormStringArray(name);
return Array.ConvertAll<string, float>(strArray, delegate(string str)
{
return float.Parse(str);
});
}
/// <summary>
/// 从Query获取float参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static float[] QueryFloatArray(string name)
{
string[] strArray = QueryStringArray(name);
return Array.ConvertAll<string, float>(strArray, delegate(string str)
{
return float.Parse(str);
});
}
/// <summary>
/// 从Form和Query获取float类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static float GetFloat(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return float.Parse(str);
}
/// <summary>
/// 从Form和Query获取float类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static float GetFloat(string name, float defaultValue)
{
try
{
return GetFloat(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form和Query获取float类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static float? GetNullableFloat(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) return null;
return float.Parse(str);
}
/// <summary>
/// 从Form和Query获取float类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static float? GetNullableFloat(string name, float? defaultValue)
{
try
{
return GetNullableFloat(name);
}
catch
{
return defaultValue;
}
}
/*================Double类型参数获取================*/
/// <summary>
/// 从Form获取double类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static double FormDouble(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return double.Parse(str);
}
/// <summary>
/// 从Form获取double类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static double FormDouble(string name, double defaultValue)
{
try
{
return FormDouble(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取double类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static double? FormNullableDouble(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) return null;
return double.Parse(str);
}
/// <summary>
/// 从Form获取double类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static double? FormNullableDouble(string name, double? defaultValue)
{
try
{
return FormNullableDouble(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取double类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static double QueryDouble(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return double.Parse(str);
}
/// <summary>
/// 从Query获取double类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static double QueryDouble(string name, double defaultValue)
{
try
{
return QueryDouble(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取double类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static double? QueryNullableDouble(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) return null;
return double.Parse(str);
}
/// <summary>
/// 从Query获取double类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static double? QueryNullableDouble(string name, double? defaultValue)
{
try
{
return QueryNullableDouble(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取double类型参数的数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static double[] FormDoubleArray(string name)
{
string[] strArray = FormStringArray(name);
return Array.ConvertAll<string, double>(strArray, delegate(string str)
{
return double.Parse(str);
});
}
/// <summary>
/// 从Query获取double类型的参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static double[] QueryDoubleArray(string name)
{
string[] strArray = QueryStringArray(name);
return Array.ConvertAll<string, double>(strArray, delegate(string str)
{
return double.Parse(str);
});
}
/// <summary>
/// 从Form和Query获取double类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static double GetDouble(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return double.Parse(str);
}
/// <summary>
/// 从Form和Query获取double类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static double GetDouble(string name, double defaultValue)
{
try
{
return GetDouble(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form和Query获取double类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static double? GetNullableDouble(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) return null;
return double.Parse(str);
}
/// <summary>
/// 从Form和Query获取double类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static double? GetNullableDouble(string name, double? defaultValue)
{
try
{
return GetNullableDouble(name);
}
catch
{
return defaultValue;
}
}
/*================Decimal类型============================*/
/// <summary>
/// 从Form获取decimal类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static decimal FormDecimal(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return decimal.Parse(str);
}
/// <summary>
/// 从Form获取decimal类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static decimal FormDecimal(string name, decimal defaultValue)
{
try
{
return FormDecimal(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取decimal类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static decimal? FormNullableDecimal(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) return null;
return decimal.Parse(str);
}
/// <summary>
/// 从Form获取decimal类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static decimal? FormNullableDecimal(string name, decimal? defaultValue)
{
try
{
return FormNullableDecimal(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取decimal类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static decimal QueryDecimal(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return decimal.Parse(str);
}
/// <summary>
/// 从Query获取decimal类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static decimal QueryDecimal(string name, decimal defaultValue)
{
try
{
return QueryDecimal(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取decimal类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static decimal? QueryNullableDecimal(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) return null;
return decimal.Parse(str);
}
/// <summary>
/// 从Query获取decimal类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static decimal? QueryNullableDecimal(string name, decimal? defaultValue)
{
try
{
return QueryNullableDecimal(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取decimal类型参数的数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static decimal[] FormDecimalArray(string name)
{
string[] strArray = FormStringArray(name);
return Array.ConvertAll<string, decimal>(strArray, delegate(string str)
{
return decimal.Parse(str);
});
}
/// <summary>
/// 从Query获取decimal类型的参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static decimal[] QueryDecimalArray(string name)
{
string[] strArray = QueryStringArray(name);
return Array.ConvertAll<string, decimal>(strArray, delegate(string str)
{
return decimal.Parse(str);
});
}
/// <summary>
/// 从Form和Query获取decimal类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static decimal GetDecimal(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return decimal.Parse(str);
}
/// <summary>
/// 从Form和Query获取decimal类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static decimal GetDecimal(string name, decimal defaultValue)
{
try
{
return GetDecimal(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form和Query获取decimal类型参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static decimal? GetNullableDecimal(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) return null;
return decimal.Parse(str);
}
/// <summary>
/// 从Form和Query获取decimal类型参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static decimal? GetNullableDecimal(string name, decimal? defaultValue)
{
try
{
return GetNullableDecimal(name);
}
catch
{
return defaultValue;
}
}
/*================DateTime类型参数获取================*/
/// <summary>
/// 从Form获取DateTime类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime FormDateTime(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return DateTime.Parse(str);
}
/// <summary>
/// 从Form获取DateTime类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static DateTime FormDateTime(string name, DateTime defaultValue)
{
try
{
return FormDateTime(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取DateTime类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime? FormNullableDateTime(string name)
{
string str = FormString(name);
if (string.IsNullOrEmpty(str)) return null;
return DateTime.Parse(str);
}
/// <summary>
/// 从Form获取DateTime类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static DateTime? FormNullableDateTime(string name, DateTime? defaultValue)
{
try
{
return FormNullableDateTime(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取DateTime类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime QueryDateTime(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return DateTime.Parse(str);
}
/// <summary>
/// 从Query获取DateTime类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static DateTime QueryDateTime(string name, DateTime defaultValue)
{
try
{
return QueryDateTime(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Query获取DateTime类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime? QueryNullableDateTime(string name)
{
string str = QueryString(name);
if (string.IsNullOrEmpty(str)) return null;
return DateTime.Parse(str);
}
/// <summary>
/// 从Query获取DateTime类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static DateTime? QueryNullableDateTime(string name, DateTime? defaultValue)
{
try
{
return QueryNullableDateTime(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form获取DateTime类型参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime[] FormDateTimeArray(string name)
{
string[] strArray = FormStringArray(name);
return Array.ConvertAll<string, DateTime>(strArray, delegate(string str)
{
return DateTime.Parse(str);
});
}
/// <summary>
/// 从Query获取DateTime类型参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime[] QueryDateTimeArray(string name)
{
string[] strArray = QueryStringArray(name);
return Array.ConvertAll<string, DateTime>(strArray, delegate(string str)
{
return DateTime.Parse(str);
});
}
/// <summary>
/// 从Form获取DateTime?类型的参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime?[] FormNullableDateTimeArray(string name)
{
string[] strArray = FormStringArray(name);
return Array.ConvertAll<string, DateTime?>(strArray, delegate(string str)
{
if (string.IsNullOrEmpty(str)) return null;
return DateTime.Parse(str);
});
}
/// <summary>
/// 从Query获取DateTime?类型的参数数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime?[] QueryNullableDateTimeArray(string name)
{
string[] strArray = QueryStringArray(name);
return Array.ConvertAll<string, DateTime?>(strArray, delegate(string str)
{
if (string.IsNullOrEmpty(str)) return null;
return DateTime.Parse(str);
});
}
/// <summary>
/// 从Form和Query获取DateTime类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime GetDateTime(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) throw new Exception("没有名为“" + name + "”的参数!");
return DateTime.Parse(str);
}
/// <summary>
/// 从Form和Query获取DateTime类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static DateTime GetDateTime(string name, DateTime defaultValue)
{
try
{
return GetDateTime(name);
}
catch
{
return defaultValue;
}
}
/// <summary>
/// 从Form和Query获取DateTime类型的参数
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static DateTime? GetNullableDateTime(string name)
{
string str = GetString(name);
if (string.IsNullOrEmpty(str)) return null;
return DateTime.Parse(str);
}
/// <summary>
/// 从Form和Query获取DateTime类型的参数,如果获取或转换失败,返回默认值
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public static DateTime? GetNullableDateTime(string name, DateTime? defaultValue)
{
try
{
return GetNullableDateTime(name);
}
catch
{
return defaultValue;
}
}
/*================HttpPostedFile类型参数获取================*/
/// <summary>
/// 获取指定参数名的文件
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static HttpPostedFile GetPostedFile(string name)
{
return Request.Files[name];
}
/// <summary>
/// 获取指定参数名的文件数组
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static HttpPostedFile[] GetPostedFileArray(string name)
{
List<HttpPostedFile> list = new List<HttpPostedFile>();
string[] names = Request.Files.AllKeys;
for (int i = 0; i < names.Length; i++)
{
if (names[i] == name)
{
list.Add(Request.Files.Get(i));
}
}
return list.ToArray();
}
/// <summary>
/// 获得当前页面客户端的IP
/// </summary>
/// <returns>当前页面客户端的IP</returns>
public static string GetIp()
{
string result = String.Empty;
result = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(result))
{
result = Request.ServerVariables["REMOTE_ADDR"];
}
if (string.IsNullOrEmpty(result))
{
result = Request.UserHostAddress;
}
if (string.IsNullOrEmpty(result))
{
return "127.0.0.1";
}
return result;
}
/// <summary>
/// 得到主机头
/// </summary>
/// <returns></returns>
public static string GetHost()
{
return Request.Url.Host;
}
/// <summary>
/// 获得当前完整Url地址
/// </summary>
/// <returns>当前完整Url地址</returns>
public static string GetUrl()
{
return Request.Url.ToString();
}
/// <summary>
/// 判断当前页面是否接收到了Post请求
/// </summary>
/// <returns>是否接收到了Post请求</returns>
public static bool IsPost()
{
return Request.HttpMethod.Equals("POST");
}
/// <summary>
/// 判断当前页面是否接收到了Get请求
/// </summary>
/// <returns>是否接收到了Get请求</returns>
public static bool IsGet()
{
return Request.HttpMethod.Equals("GET");
}
}
}
http 协议集合,超级简单的更多相关文章
- (转)用JS获取地址栏参数的方法(超级简单)
转自http://www.cnblogs.com/fishtreeyu/archive/2011/02/27/1966178.html 用JS获取地址栏参数的方法(超级简单) 方法一:采用正则表达式获 ...
- JS基础(超级简单)
1 JS基础(超级简单) 1.1 数据类型 1.1.1 基本类型: 1) Number:特别注意:NaN的检测方法:Nan!=NaN;或者使用isNaN方法 2) ...
- JavaScript,一个超级简单的方法判断浏览器的内核前缀
先说明,此处的方法是说超级简单的方法,不是指代码超级少,而是用非常简单的知识点,只要懂得怎么写JavaScript的行内样式就可以判断. 大家应该还记得JavaScript行内样式怎么写吧?(看来我是 ...
- zw版_Halcon图像交换、数据格式、以及超级简单实用的DIY全内存计算.TXT
zw版_Halcon图像交换.数据格式.以及超级简单实用的DIY全内存计算.TXT Halcon由于效率和其他原因,内部图像采用了很多自有格式,提高运行速度,但在数据交换方面非常麻烦. 特别是基于co ...
- phpexcelreader超级简单使用
phpexcelreader超级简单使用 该php类可以到官网下载:http://www.codeplex.com/PHPExcel,下载的文件不能直接使用要看下面的备注. 备注: 1.要将olere ...
- 哈,又一款超级简单的队列(MQ)实现方案来了~
开源的消息队列已经很多了,但大部分很重,实际环境下,很多可能只是使用到了一点功能而已,杀鸡使用牛刀,着实有些浪费了.很多时候,我们只想要一片绿叶,但它们给了我们整个的春天,很难消化.本着DIR精神, ...
- JQuery -> 超级简单的下拉菜单
使用jquery实现一个超级简单的下拉菜单. 效果图 最初的效果 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvRmVlTGFuZw==/font/5a6L ...
- html超级简单实现点赞(收藏)和取消赞效果
1.前言 我们经常会遇到对一些列表呀进行点赞呀收藏数据等效果呀.今天就用html+css实现超级简单易上手的点赞和取消赞的demo展示. 2.详情 1.css样式 .like{ font-size:6 ...
- Android高级控件(四)——VideoView 实现引导页播放视频欢迎效果,超级简单却十分的炫酷
Android高级控件(四)--VideoView 实现引导页播放视频欢迎效果,超级简单却十分的炫酷 是不是感觉QQ空间什么的每次新版本更新那炫炫的引导页就特别的激动,哈哈,其实他实现起来真的很简单很 ...
- 超级简单的数据压缩算法—LZW算法
1. 前文回顾 在字符串算法—数据压缩中,我们介绍了哈夫曼压缩算法(Huffman compression),本文将介绍LZW算法. 2. LZW算法 这个算法很简单,为了方便讲述,我们将采用16进制 ...
随机推荐
- WPF整理-XAML访问静态属性
"XAML provides an easy way to set values of properties—type converters and the extended propert ...
- c++聪聪看书(低数据版代码)
聪聪是一个善良可爱.睿智聪慧的好孩子.聪聪喜欢看书,这一天她在看一本书时看到了这样一个问题:给你一个正整数n,你要将它分成若干个自然数Ai的和的形式,并且使得这若干个自然数Ai的乘积尽量大,并输出最大 ...
- 野路子出身PowerShell 文件操作实用功能 MSSQL123
因工作需要,处理一批文件,本想写C#来处理的,后来想想这个是PowerShell的天职, 索性就网上各种搜,各种Demo,各种修改,花了半天时间,最后还是拼凑出来能达到效果了. 本身对PowerShe ...
- C# 依赖注入
http://www.cnblogs.com/leoo2sk/archive/2009/06/17/1504693.html 这篇文章真的非常非常好···绝对值得收藏学习. 目录 目录 1 ...
- EXCEL技巧——SUBTOTAL函数巧妙应用
想用COUNTA来计算非空单元格的数量,但它会把隐藏的单元格也算进去,所以用到了SUBTOTAL这个函数.做个记录,方便日后使用 函数表示: SUBTOTAL(function_num, ref1, ...
- 使用Java开发高性能网站需要关注的那些事儿
无论大型门户网站还是中小型垂直类型网站都会对稳定性.性能和可伸缩性有所追求.大型网站的技术经验分享值得我们去学习和借用,但落实到更具体的实践上并不是对所有网站可以适用,其他语言开发的网站我还不敢多说, ...
- ECMAScript Web APIs node.js
https://hacks.mozilla.org/2015/04/es6-in-depth-an-introduction/ What falls under the scope of ECMASc ...
- c语言编程
1.常量和变量:变量是一块内存空间,该内存空间有类型约束,该内存中存放的数据可变. 变量三要素:类型,名称,值.常量:常量的数据永远不变,a:自变量,b:符合常量,c:预定义常量. 2.运算符和返回类 ...
- linux安装jdk和scala
安装jdk 1.下载jdk 2.在linux中创建一个文件夹java,我习惯放在user下 3.上传jdk安装包到java下,然后解压 4.ect/profile下修改文件,添加环境变量 JAVA_H ...
- ztree获取当前选中节点子节点id集合的方法(转载)
本文实例讲述了ztree获取当前选中节点子节点id集合的方法.分享给大家供大家参考.具体分析如下: 要求:获取当前选中节点的子节点id集合. 步骤: 1.获取当前节点 2.用ztree的方法trans ...