SendFileResponse as now the default parameter folder = "resources"
add a function GetPostParams
This commit is contained in:
parent
b8fb0e7278
commit
b3d60ad1ae
@ -37,6 +37,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
@ -1,17 +1,15 @@
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
using LitJson;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using BlubbFish.Utils.IoT.Events;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.Utils.IoT.Bots
|
||||
{
|
||||
namespace BlubbFish.Utils.IoT.Bots {
|
||||
public abstract class Webserver
|
||||
{
|
||||
protected Dictionary<String, String> config;
|
||||
@ -42,7 +40,7 @@ namespace BlubbFish.Utils.IoT.Bots
|
||||
});
|
||||
}
|
||||
|
||||
public static Boolean SendFileResponse(HttpListenerContext cont, String folder) {
|
||||
public static Boolean SendFileResponse(HttpListenerContext cont, String folder = "resources") {
|
||||
String restr = cont.Request.Url.PathAndQuery;
|
||||
if(restr.StartsWith("/")) {
|
||||
if(restr.IndexOf("?") != -1) {
|
||||
@ -111,6 +109,26 @@ namespace BlubbFish.Utils.IoT.Bots
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Dictionary<String, String> GetPostParams(HttpListenerRequest req) {
|
||||
if(req.HttpMethod == "POST") {
|
||||
if(req.HasEntityBody) {
|
||||
StreamReader reader = new StreamReader(req.InputStream, req.ContentEncoding);
|
||||
String rawData = reader.ReadToEnd();
|
||||
req.InputStream.Close();
|
||||
reader.Close();
|
||||
Dictionary<String, String> ret = new Dictionary<String, String>();
|
||||
foreach(String param in rawData.Split('&')) {
|
||||
String[] kvPair = param.Split('=');
|
||||
if(!ret.ContainsKey(kvPair[0])) {
|
||||
ret.Add(kvPair[0], HttpUtility.UrlDecode(kvPair[1]));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return new Dictionary<String, String>();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
this.httplistener.Stop();
|
||||
this.httplistener.Close();
|
||||
|
Loading…
Reference in New Issue
Block a user