You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
1.9 KiB
92 lines
1.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
|
|
using Sog;
|
|
using SimpleHttpServer;
|
|
|
|
namespace SMWebServer
|
|
{
|
|
/// <summary>
|
|
/// http请求参数列表
|
|
/// </summary>
|
|
public class HttpQueryParams
|
|
{
|
|
public Dictionary<string, string> m_map = new Dictionary<string, string>();
|
|
|
|
public HttpQueryParams(string url, bool replaceAdd = true)
|
|
{
|
|
Parse(url, replaceAdd);
|
|
}
|
|
|
|
public HttpQueryParams()
|
|
{
|
|
|
|
}
|
|
|
|
private void Parse(string url,bool replaceAdd = true)
|
|
{
|
|
if(url == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int indexend = url.IndexOf('?');
|
|
|
|
string paramStr = url.Substring(indexend + 1, url.Length - (indexend + 1));
|
|
|
|
string[] allParams = paramStr.Split('&');
|
|
|
|
foreach(var param in allParams)
|
|
{
|
|
string[] namevalue = param.Split('=');
|
|
if (namevalue != null && namevalue.Length == 2)
|
|
{
|
|
TraceLog.Trace("namevalue[1] {0}", namevalue[1]);
|
|
|
|
//if (replaceAdd)
|
|
{
|
|
namevalue[1] = namevalue[1].Replace("+", "%20");
|
|
}
|
|
string value = Uri.UnescapeDataString(namevalue[1]);
|
|
if (m_map.ContainsKey(namevalue[0]))
|
|
{
|
|
m_map[namevalue[0]] = value; //等同于 title=1654sdf
|
|
}
|
|
else
|
|
{
|
|
m_map.Add(namevalue[0], value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string GetValue(string name)
|
|
{
|
|
if(m_map.ContainsKey(name))
|
|
{
|
|
return m_map[name];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void AddNameValue(string name,string value)
|
|
{
|
|
if (m_map.ContainsKey(name))
|
|
{
|
|
m_map[name] = value;
|
|
}
|
|
else
|
|
{
|
|
m_map.Add(name, value);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public int Count { get { return m_map.Count; } }
|
|
}
|
|
}
|
|
|