/// <summary>
/// 將獲取的formData存入字典數組
/// </summary>
public static Dictionary<String, String> GetFormData(string formData)
{
try
{
//將參數存入字符數組
String[] dataArry = formData.Split('&');數組
//定義字典,將參數按照鍵值對存入字典中
Dictionary<String, String> dataDic = new Dictionary<string, string>();
//遍歷字符數組
for (int i = 0; i <= dataArry.Length - 1; i++)
{
//當前參數值
String dataParm = dataArry[i];
//"="的索引值
int dIndex = dataParm.IndexOf("=");
//參數名做爲key
String key = dataParm.Substring(0, dIndex);
//參數值做爲Value
String value = dataParm.Substring(dIndex + 1, dataParm.Length - dIndex - 1);
//將編碼後的Value解碼
String deValue = System.Web.HttpUtility.UrlDecode(value, System.Text.Encoding.GetEncoding("utf-8"));
if (key != "__VIEWSTATE")
{
//將參數以鍵值對存入字典
dataDic.Add(key, deValue);
}
}編碼
return dataDic;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}code