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.
108 lines
2.5 KiB
108 lines
2.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
|
|
using Sog;
|
|
using SimpleHttpServer;
|
|
|
|
namespace Operation
|
|
{
|
|
/// <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("HttpQueryParams.Parse namevalue[1] {0}", namevalue[1]);
|
|
|
|
string value = "";
|
|
for (int i = 1; i < namevalue.Length; i++)
|
|
{
|
|
namevalue[i] = namevalue[i].Replace("+", "%20");
|
|
value += namevalue[i];
|
|
if(namevalue.Length > 2 & i != namevalue.Length - 1)
|
|
{
|
|
value += "=";
|
|
}
|
|
}
|
|
|
|
value = Uri.UnescapeDataString(value);
|
|
|
|
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 string GetValue(string name, string defaultValue = null)
|
|
{
|
|
if (m_map.ContainsKey(name))
|
|
{
|
|
return m_map[name];
|
|
}
|
|
|
|
return defaultValue;
|
|
}
|
|
|
|
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; } }
|
|
}
|
|
}
|
|
|